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"); } } }
原文:http://www.cnblogs.com/zsychanpin/p/6940331.html