HDU 5198 Strange Class

来源:互联网 发布:怎么删除受限的网络 编辑:程序博客网 时间:2024/05/16 09:23
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
abcbc
 

Sample Output
YESNO

暴力判断即可。

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


0 0
原创粉丝点击