Title Description:
For a given string (containing only ' z ', ' o ', ' J ' three characters), determine if he can AC.
The rules for AC are as follows:
1. Zoj can ac;
2. If the string form is XZOJX, it can also be AC, where x can be n ' o ' or null;
3. If AZBJC can AC, then Azbojac can also be AC, where a,b,c is n ' o ' or empty;
Input:
The input contains multiple sets of test cases, each with a string that contains only ' Z ', ' o ', ' J ' three characters, and the string length is less than or equal to 1000.
Output:
For a given string, if you can ac then output the string "Accepted", otherwise output "wrong Answer".
Sample input:
Zoj
Ozojo
Ozoojoo
Oozoojoooo
Zooj
Ozojo
Oooozojo
Zojoooo
Sample output:
Accepted
Accepted
Accepted
Accepted
Accepted
Accepted
Wrong Answer
Wrong Answer
#include <iostream>using namespacestd;intMain () {strings; while(cin>>s) { BOOLflag=true; intPos=s.find ('Z'); inti; for(i=0; i<pos;i++){ if(s[i]!='o') flag=false; } intPos1=s.find ('J'); for(i=pos1+1; I<s.size (); i++){ if(s[i]!='o') flag=false; } if((S.size ()-pos1-1)!=pos) flag=false; intnum=0; for(i=pos+1; i<pos1;i++){ if(s[i]!='o') flag=false; Elsenum++; } if(num==0) flag=false; if(flag) cout<<"Accepted"<<Endl; Elsecout<<"wrong Answer"<<Endl; } return 0;}
1006.ZOJ problem