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;
}


全部评论

相关推荐

到我怀里来:教育背景不用写主修课程,还有你写班级排名是什么意思?咋不写寝室排名呢😂要写就写年纪排名。得了那么多奖结果项目经历什么技术细节都不写清楚,把技术细节写清楚,用了什么技术解决了什么问题,“用了python语言、用了SQL语言”,有这样写的?hr一看就知道你是包装的或者比赛的奖是混的,你什么技术细节都不懂。校内职务全删了,什么三好学生、文明寝室这些你写上去干嘛?重复的奖学金你写三次干嘛?自我评价写那么多干嘛?谁想看这些
点赞 评论 收藏
分享
🔌插電的小米大冰箱:很喜欢放牛,因为牛不会在我翻过第四座山后跟我说第一座山的草好吃
点赞 评论 收藏
分享
2024-12-08 18:59
东北大学 Java
Java抽象带篮子:外卖项目可以看看我的详细的外卖话术,里面还写了怎么描述项目,还为了提高含金量额外增加了很多技术亮点呢。另外我这边还有个7000多字的轮子项目话术,可以狠狠的速成,需要的似我
点赞 评论 收藏
分享
joe2333:怀念以前大家拿华为当保底的日子
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务