博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
对给定的字符串(只包含'z','o','j'三种字符),判断他是否能AC。
阅读量:5049 次
发布时间:2019-06-12

本文共 1632 字,大约阅读时间需要 5 分钟。

/*

对给定的字符串(只包含'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;

         Output

        

           对于给定的字符串,如果能AC则请输出字符串“Accepted”,否则请输出“Wrong Answer”。

*/

#include<iostream>

#include<string.h>

using namespace std;

int main()

{

         char string[1000];

         char *p,*q,*l;

         int i,num1=0,num2=0,num3=0;

         bool tag=false;

         while(cin>>string)

         {

                   if(strcmp(string,"zoj")==0)

                            cout<<"Accepted"<<endl;

                   else if(strstr(string,"zoj")!=NULL)

                   {

                            p=strstr(string,"zoj");

                            for(i=0;i<strlen(string);i++)

                            {

                                     if((string[i]=='o')&&(&string[i]<p))

                                               num1++;

                                     else if(&string[i]==p)

                                               i=i+2;

                                     else if((string[i]=='o')&&(&string[i]>(p+2)))

                                               num2++;

                                     else

                                     {

                                               cout<<"Wrong Answer"<<endl;

                                               tag=true;

                                               break;

                                     }

                                    

                            }

                            if(tag==false)

                            {

                            if(num1==num2)

                                     cout<<"Accepted"<<endl;

                            else

                                     cout<<"Wrong Answer"<<endl;

                            }

                            else

                                     tag=false;

                            num1=num2=0;

                           

                   }

                   else if((strstr(string,"z")!=NULL)&&(strstr(string,"oj")!=NULL))

                   {

                            p=strstr(string,"z");

                            q=strstr(string,"oj");

                            num3=q-p;

                            for(i=0;i<strlen(string);i++)

                            {

                                     if((string[i]=='o')&&(&string[i]<p))

                                               num1++;

                                     else if(&string[i]==p)

                                     {

                                               l=p;

                                               for(l++;l<=q;l++)

                                               {

                                                        if(*l!='o')

                                                        {

                                                                 cout<<"Wrong Answer"<<endl;

                                                                 break;

                                                        }

                                               }

                                               i=i+num3+1;

                                              

                                     }

                                     else if((string[i]=='o')&&(&string[i]>(p+1+num3)))

                                               num2++;

                                     else

                                     {

                                               cout<<"Wrong Answer"<<endl;

                                               tag=true;

                                               break;

                                     }

                                    

                            }

                            if(tag==false)

                            {

                            if(num3*num1==num2)

                                     cout<<"Accepted"<<endl;

                            else

                                     cout<<"Wrong Answer"<<endl;

                            }

                            else

                                     tag=false;

                            num1=num2=num3=0;

                   }

                   else

                            cout<<"Wrong Answer"<<endl;

                  

         }       

         return 0;

}

/*

zoj

ozojo

ozoojoo

oozoojoooo

zooj

ozojo

oooozojo

zojoooo

*/

转载于:https://www.cnblogs.com/-wang-xin/archive/2012/11/23/2785114.html

你可能感兴趣的文章
【19】AngularJS 应用
查看>>
Spring
查看>>
Linux 系统的/var目录
查看>>
Redis学习---Redis操作之其他操作
查看>>
WebService中的DataSet序列化使用
查看>>
BZOJ 1200 木梳
查看>>
【Linux】【C语言】菜鸟学习日志(一) 一步一步学习在Linxu下测试程序的运行时间...
查看>>
hostname
查看>>
SpringBoot使用其他的Servlet容器
查看>>
关于cookie存取中文乱码问题
查看>>
k8s架构
查看>>
select 向上弹起
查看>>
mysql 多表管理修改
查看>>
group by order by
查看>>
bzoj 5252: [2018多省省队联测]林克卡特树
查看>>
https 学习笔记三
查看>>
Oracle学习之简单查询
查看>>
log4j配置
查看>>
linux 配置SAN存储-IPSAN
查看>>
双链表
查看>>