http://ac.jobdu.com/problem.php?pid=1006
#include <iostream> #include <cstdio> #include <string> using namespace std; #define rep(i,j,k) for(int i=j;i<=k;i++) bool ac(string s) { //cout << s << endl; int len = s.size(); if (len < 3) return false; if (s == "zoj") return true; int i = 0, j = len - 1; while (i < j) { if (s[i] == s[j] && s[i] == 'o') { i++; j--; } else break; } if (j - i == 2 && s[i] == 'z' && s[i + 1] == 'o' && s[j] == 'j') return true; if (s[i] == 'z') { s.erase(s.begin() + j+1, s.end()); int jI = s.find_last_of("j"); if (s[jI - 1] != 'o') return false; s.erase(s.begin() + jI - 1); // cout << "s:" << s << endl; return ac(s); } return false; } int main() { string s; while (cin >> s) { printf("%s\n",ac(s)?"Accepted":"Wrong Answer"); } return 0; }