bestcoder#36-13981Strange Class字符串是否是a^n+b^n+c^n

Problem Description
In Vivid’s school, there is a strange class(SC). In SC, the students’ names are very strange. They are in the same format:  anbncn(a,b,c must not be the same with each other). For example studens whose names are“abc”,”ddppqq” are in SC, however studens whose names are “aaa”,“ab”,”ddppqqq” are not in SC.
Vivid makes friends with so many students, he wants to know who are in SC.
 

Input
There are multiple test cases (about 10), each case will give a string S which is the name of Vivid’s friend in a single line.
Please process to the end of file.

[Technical Specification]

1|S|10.

|S| indicates the length of S.

S only contains lowercase letter.
 

Output
For each case, output YES if Vivid’s friend is the student of SC, otherwise output NO.
 

Sample Input
abc bc
 

Sample Output
YES NO
 


肯定是写麻烦了==

#include <iostream>
#include<cstring>
#include<cstdio>
using namespace std;
char s[11];
int main()
{
    while(~scanf("%s",s))
    {
         int len=strlen(s);
         int t=len/3;
         if(len%3) printf("NO\n");
         else
         {
              if(t==1)
              {
                   if(s[0]!=s[1]&&s[1]!=s[2]&&s[0]!=s[2]) printf("YES\n");
                   else printf("NO\n");
              }
              else
              {
                   int mark=0;
                   for(int i=0;i<t-1;i++)
                   {
                         if(s[i]!=s[i+1])
                         {
                              printf("NO\n");
                              mark=1;
                              break;
                         }
                   }
                   for(int i=t;i<2*t-1;i++)
                   {
                         if(mark) break;
                         if(s[i]!=s[i+1])
                         {
                              printf("NO\n");
                              mark=1;
                              break;
                         }
                   }
                   for(int i=2*t;i<3*t-1;i++)
                   {
                         if(mark) break;
                         if(s[i]!=s[i+1])
                         {
                              printf("NO\n");
                              mark=1;
                              break;
                         }
                   }
                   if(!mark)
                   {
                       if(s[0]!=s[t]&&s[0]!=s[2*t]&&s[t]!=s[2*t])
                        printf("YES\n");
                        else printf("NO\n");
                   }
              }
         }
    }
    return 0;
}


全部评论

相关推荐

05-13 00:41
已编辑
北京邮电大学 Java
理性的杰克刷牛客:ai肯定要有的,最好学一下agent方向加一个智能客服什么的进去,并且多加点什么skill,mcp啥的,另外你现在的项目深度有些浅,这些功能都太简单了,而且也不是真正能扛高并发的实现,没有什么太大的亮点,可以去网上找点更有深度的项目。可以先投一些中小厂,有实习经历以后再去大厂,你现在这个大厂可能机会不大
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务