Strange Class

来源:互联网 发布:上海至寻网络怎么样 编辑:程序博客网 时间:2024/06/06 03:07

Strange Class

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 675 Accepted Submission(s): 367


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<iostream>using namespace std;struct pt{char a;int t;}m[30];int main(){string s;while(cin>>s){int str = s.size() ;if(str%3 != 0){cout<<"NO"<<endl;continue;}int count = 1;m[0].a = s[0];m[0].t = 1;int j = 0;for(int i = 1; i< str; i ++){if(s[i] != s[i-1]){count++;m[++j].a  = s[i];m[j].t = 1;}else{m[j].t ++;}}if(count != 3){cout<<"NO"<<endl;}else{if(m[0].t == m[1].t && m[1].t ==m[2].t )  cout<<"YES"<<endl;         else         cout<<"NO"<<endl;}//cout<<m[0].a <<" "<<m[1].a <<" "<<m[2].a <<endl;//cout<<m[0].t <<" "<<m[1].t <<" "<<m[2].t <<endl;}}

1Y。。。
0 0