题目1006:ZOJ问题
时间限制:1 秒
内存限制:32 兆
特殊判题:否
提交:20252
解决:3544
- 题目描述:
-
对给定的字符串(只包含'z','o','j'三种字符),判断他是否能AC。
是否AC的规则如下: 1. zoj能AC; 2. 若字符串形式为xzojx,则也能AC,其中x可以是N个'o' 或者为空; 3. 若azbjc 能AC,则azbojac也能AC,其中a,b,c为N个'o'或者为空;
- 输入:
-
输入包含多组测试用例,每行有一个只包含'z','o','j'三种字符的字符串,字符串长度小于等于1000。
- 输出:
-
对于给定的字符串,如果能AC则请输出字符串“Accepted”,否则请输出“Wrong Answer”。
- 样例输入:
-
zoj ozojo ozoojoo oozoojoooo zooj ozojo oooozojo zojoooo
- 样例输出:
-
Accepted Accepted Accepted Accepted Accepted Accepted Wrong Answer Wrong Answer
1 #include <cstdio> 2 #include <cstdlib> 3 #include <cstring> 4 #include <string> 5 6 char s[1005]; 7 8 int main(int argc, char const *argv[]){ 9 //freopen("input.txt","r",stdin); 10 while(scanf("%s",s) != EOF) { 11 int a,b,c; 12 a = 0, b = 0, c = 0; 13 int state = 0; 14 for(int i = 0; i < strlen(s); i++){ 15 if(state == 0 && s[i] == 'o') { 16 a++; 17 } 18 else if(state == 0 && s[i] == 'z') { 19 state = 1; 20 } 21 else if(state == 0 && s[i] == 'j') { 22 break; 23 } 24 else if(state ==1 && s[i] == 'o') { 25 b++; 26 state = 2; 27 } 28 else if(state ==1 && s[i] == 'z') { 29 break; 30 } 31 else if(state ==1 && s[i] == 'j') { 32 break; 33 } 34 else if(state ==2 && s[i] == 'o') { 35 b++; 36 } 37 else if(state == 2 && s[i] == 'j') { 38 state = 3; 39 } 40 else if(state ==2 && s[i] == 'z') { 41 break; 42 } 43 else if(state == 3 && s[i] == 'o') { 44 c++; 45 } 46 else if(state == 3 && s[i] == 'z') { 47 state = 4; 48 } 49 else if(state == 3 && s[i] == 'j') { 50 state = 4; 51 } 52 } 53 54 if(c == a * b && state == 3) { 55 printf("%s ","Accepted"); 56 } 57 else { 58 printf("%s ","Wrong Answer"); 59 } 60 } 61 return 0; 62 }
这个题看似简单,但容易做错