HDU-3788
Posted 1625--h
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU-3788相关的知识,希望对你有一定的参考价值。
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
1 #include <iostream> 2 #include <string> 3 using namespace std; 4 int main() 5 { 6 int end, count1, count2, count3, flag; 7 string a; 8 while (cin >> a) 9 { 10 flag = 1; 11 count1 = count2 = count3 = 0; 12 end = 0; 13 for (int i = 0; i < a.length(); i++) 14 { 15 if (flag == 1) 16 { 17 if (a.at(i) == ‘o‘) 18 { 19 count1++; 20 continue; 21 } 22 else if (a.at(i) == ‘z‘) 23 { 24 flag = 2; 25 continue; 26 } 27 else if (a.at(i) == ‘j‘) 28 { 29 end = 1; 30 break; 31 } 32 } 33 if (flag == 2) 34 { 35 if (a.at(i) == ‘o‘) 36 { 37 count2++; 38 continue; 39 } 40 else if (a.at(i) == ‘j‘) 41 { 42 flag = 3; 43 continue; 44 } 45 else if (a.at(i) == ‘z‘) 46 { 47 end = 1; 48 break; 49 } 50 } 51 if (flag == 3) 52 { 53 if (a.at(i) == ‘o‘) 54 { 55 count3++; 56 continue; 57 } 58 else 59 { 60 end = 1; 61 break; 62 } 63 } 64 } 65 if (end) 66 { 67 printf("Wrong Answer "); 68 } 69 else 70 { 71 if (flag ==3&&count1*count2 == count3&&count2) 72 printf("Accepted "); 73 else 74 printf("Wrong Answer "); 75 } 76 } 77 return 0; 78 }
以上是关于HDU-3788的主要内容,如果未能解决你的问题,请参考以下文章