HDU 5198 Strange Class

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<stdio.h>
#include<iostream>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cstdlib>
#include<functional>
#include<string>
#include<cstring>
using namespace std;
const int maxn = 4;
char s[100];

void check()
{
    int n = strlen(s);
    if (n % 3 != 0) { printf("NO\n"); return; }
    for (int i = 0; i < n / 3; i++)
    if (s[i] != s[0]) { printf("NO\n"); return; }
    for (int i = n / 3; i < 2 * n / 3; i++)
    if (s[i] != s[n / 3]) { printf("NO\n"); return; }
    for (int i = 2 * n / 3; i < n; i++)
    if (s[i] != s[2 * n / 3]) { printf("NO\n"); return; }
    if (s[0] == s[n / 3] || s[n / 3] == s[n / 3 * 2] || s[0] == s[n / 3 * 2])
    {
        printf("NO\n"); return;
    }
    printf("YES\n");
}

int main()
{
    while (scanf("%s", s) != EOF) check();
}


你可能感兴趣的:(HDU,暴力求解)