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


你可能感兴趣的:(算法,HDU)