Zoj problemsTime limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total Submission (s): 2900 Accepted Submission (s): 877
problem Descriptionfor 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;
InputThe input contains multiple sets of test cases, each line has a string containing only ' Z ', ' o ', ' J ' three characters, the string length is less than or equal to three;
Outputfor a given string, if you can ac then output the string "Accepted", otherwise output "wrong Answer".
Sample Input
Zojozojoozoojoooozoojoooozoojozojooooozojozojoooo
Sample Output
Acceptedacceptedacceptedacceptedacceptedacceptedwrong Answerwrong Answer
Problem Solving Ideas:
Condition two and condition three to combine to understand, finally will find the following rule:
Set: A = number of First z before O
b = Number of o sandwiched between Z and J
c = Number of O after the first J
Then conditional two or three is:
A,b,c Meet A*b=c
And the xzojx of condition two just meet the above conditions
It is also important to note that b>0, such as input ZJ, should be the output of WA instead of ACCode
#include <stdio.h> #include <string.h>char zoj[1100];int main () {int len,now,ok;int a,b,c;int i,j,k;while ( Gets (Zoj)!=null) {Len=strlen (ZOJ); ok=0;now=0;a=b=c=0;//determines the number of a,b,c for (i=0;i<len&&zoj[i]!= ' z '; i++) {if ( zoj[i]== ' o ')//guaranteed to be O { a++; now++; } else { ok=1; break; }} Now+=1;for (i=now;i<len&&zoj[i]!= ' j '; i++) {if (zoj[i]== ' O ') { b++; now++; } else { ok=1; break; }} Now+=1;for (i=now;i<len;i++) {if (zoj[i]== ' O ') { C + +; } else { ok=1; break; }} if (ok==1) printf ("Wrong answer\n"); else{ if (b!=0&&c==a*b) printf ("accepted\n");/* Condition two and condition three to combine to understand, finally will find the following rule: set: A = number of the first z o = number of o between Z and j C = number of O after the first J is conditional two or three: a , B, C satisfies a*b=c and b!=0 * /Else printf ("wrong answer\n");}} return 0;}
1412111853-hd-zoj problems