- 题目描述:
-
对给定的字符串(只包含‘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
#include <iostream> #include <cstring> #include <stdio.h> using namespace std; bool accept1(char str[]) { int i = 0; bool isZ = false; bool isO = false; bool isJ = false; while(str[i]) { if(i == 0 && str[i] == 'z') isZ = true; if(i == 1 && str[i] == 'o') isO = true; if(i == 2 && str[i] == 'j') isJ = true; i++; } if(isZ && isO && isJ && i == 3) return true; else return false; } //xzojx bool accept2(char str[]) { int i = 2; bool flag = false; if(str[0] && str[1]) { while(str[i]) { if(str[i] == 'j' && str[i - 1] == 'o' && str[i - 2] == 'z') { int cishu = i -2 ; bool is_equal = true; int j =0; for(; j < cishu; j++) { if(str[j] == 'o' && str[i+1+j] == 'o') continue; else { is_equal = false; break; } } if(is_equal && !str[j+i+1]) { flag = true; break; } } i++; } } return flag; } // azbojac oozoojoooo bool accept3(char str[]) { int i = 0; int a=0,b=0,c=0; int numZ =0,numJ=0; bool hasZ = false,hasO = false,hasJ = false; bool flag = false; while(str[i]) { if(str[i] == 'z' ) { numZ++; hasZ = true; } if(str[i] == 'j') { numJ++; hasJ = true; } if(!hasZ && str[i] == 'o') a++; if(hasZ && !hasJ && str[i] == 'o') b++; if(hasZ && hasJ && str[i] == 'o') c++; i++; } if(numJ == 1 && numZ == 1) { if(2*a == c && b >= 1) flag = true; } return flag; } int main() { char str[1000]; //string str; while(scanf("%s",str) != EOF) { if(accept1(str) || accept2(str) || accept3(str)) { printf("%s\n","Accepted"); } else { printf("%s\n","Wrong Answer"); } } }
时间: 2024-12-21 03:57:07