ZOJ问题
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3269 Accepted Submission(s): 974
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
Source
Recommend
notonlysuccess | We have carefully selected several similar problems for you:
3790
3791
3789
3787
3786
//坑点:
<1>:串中一定有'Z', 'J'; 'Z', 'J'中间一定有‘O’
<2>:对于满足<1>的串,如a ‘Z’ b 'J' c 一定满足 a*b=c || a=c=0;
<3>:oooooozj →→ Wrong Answer;
1 #include <stdio.h> 2 #include <string.h> 3 int main() 4 { 5 char str[1010]; 6 while(~scanf("%s", str)) 7 { 8 char ch[2] = {'0', '0'}; 9 int i, t, h, total = 0; 10 int len = strlen(str); 11 int num[3] = {0, 0, 0}; 12 int flag = 0; 13 if(len<=2) 14 { 15 printf("Wrong Answer\n"); 16 continue; 17 } 18 for(t=0, h=0, i=0; i<len; i++) 19 { 20 if(str[i] == 'o') 21 total++; 22 if(str[i] != 'o' || i == len-1) 23 { 24 ch[h++] = str[i]; 25 num[t++] += total; 26 total = 0; 27 continue; 28 } 29 } 30 31 // num[t++] = total; 32 if(num[0]*num[1] == num[2] && ch[0]=='z' && ch[1] == 'j' && num[1]!=0) 33 printf("Accepted\n"); 34 else 35 printf("Wrong Answer\n"); 36 } 37 return 0; 38 }