ZOJ问题
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3221 Accepted Submission(s): 963
Problem Description
对给定的字符串(只包含'z','o','j'三种字符),判断他是否能AC。
是否AC的规则如下:
1. zoj能AC;
2. 若字符串形式为xzojx,则也能AC,其中x可以是N个'o' 或者为空;
3. 若azbjc 能AC,则azbojac也能AC,其中a,b,c为N个'o'或者为空;
是否AC的规则如下:
1. zoj能AC;
2. 若字符串形式为xzojx,则也能AC,其中x可以是N个'o' 或者为空;
3. 若azbjc 能AC,则azbojac也能AC,其中a,b,c为N个'o'或者为空;
Input
输入包含多组测试用例,每行有一个只包含'z','o','j'三种字符的字符串,字符串长度小于等于1000;
Output
对于给定的字符串,如果能AC则请输出字符串“Accepted”,否则请输出“Wrong Answer”。
Sample Input
zoj ozojo ozoojoo oozoojoooo zooj ozojo oooozojo zojoooo
Sample Output
Accepted Accepted Accepted Accepted Accepted Accepted Wrong Answer Wrong Answer
题解:规律题,1:x*b=z;2:z,j出现一次,o必须出现,3:z在j前边;坑了10多次、、、、、、
代码:
1 #include<stdio.h> 2 #include<string.h> 3 char m[1010]; 4 int judge(){ 5 int t=strlen(m); 6 int x=0,y=0,a=0,b=0,c=0,z=0; 7 for(int i=0;i<t;++i){ 8 if(m[i]=='z')a++; 9 if(m[i]=='o')b++; 10 if(m[i]=='j')c++; 11 //if(m[i]!='z'&&m[i]!='o'&&m[i]!='j')return 0; 12 } 13 if(a!=1||b==0||c!=1)return 0; 14 a=b=c=0; 15 for(int i=0;i<t;++i){ 16 if(m[i]=='z')a++; 17 if(!a&&m[i]=='o')x++; 18 if(a&&m[i]=='o'&&!c)b++; 19 if(a&&b&&m[i]=='j')c++; 20 if(c&&m[i]=='o')z++; 21 }//printf("%d %d %d %d %d\n",a,b,c,x,z); 22 if(a!=1||!b||c!=1)return 0; 23 //if(x==z&&b)return 1; 24 if(z==b*x)return 1; 25 else return 0; 26 } 27 int main() 28 { 29 while(memset(m,0,sizeof(m)),~scanf("%s",m)){ 30 if(judge())puts("Accepted"); 31 else puts("Wrong Answer"); 32 } 33 return 0; 34 }