Problem Description
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();
}