hdu 3788 hdoj 3788

ZOJ问题

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 601    Accepted Submission(s): 186


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'或者为空;
 

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
 
#include
#include
using namespace std;
int main()
{
    int a,b,c,pass1,pass2,ok,pass3;
    string sen;
    while(cin>>sen)
    {
        pass1=0,pass2=0,a=0,b=0,c=0,ok=0,pass3=0;
        for(int i=0; i         {
            if(sen[i]!='z'&&sen[i]!='o'&&sen[i]!='j') pass3=1;
            if(sen[i]=='z')
            {
                pass1++;
            }
            if(sen[i]=='j')
            {
                pass2++;
            }
            if(sen[i]=='o')
            {
                if(!pass1&&!pass2)
                {
                    a++;
                }
                if(pass1&&!pass2)
                {
                    b++;
                }
                if(pass1&&pass2)
                {
                    c++;
                }
            }
        }
        if(a==0&&c==0&&b!=0) ok=1;
        if(a!=0&&c/a==b&&c%a==0&&b!=0) ok=1;
        if(pass1!=1||pass2!=1||pass3==1) ok=0;
        if(ok) cout<<"Accepted"<         else cout<<"Wrong Answer"<     }
    return 0;
}

你可能感兴趣的:(ACM学习笔记,output,string,input,c,测试)