暑假集训第三周周三赛 STL C - Strange Class 字符相同 SC数

来源:互联网 发布:mysql 5.6参考手册 编辑:程序博客网 时间:2024/05/29 11:13


C - Strange Class
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
Submit Status Practice HDU 5198

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: $a^{n}b^{n}c^{n}$(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 \leq |S| \leq 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

分析:

依旧是set,与上题不一样的是,这个题要的只是set的长度,也就是里边元素的个数,只要个数等于三,就可以用字符串去判断是否符合要求。

求长度set: s=it.size()

数组:s=strlen(it)

字符串:s=it.length()


1234567891011121314151617181920212223242526272829303132333435363738394041424344
#include<stdio.h>#include<set>#include<string.h>using namespace std;int main(){    int  i,j,c,l;    char a[100];    set<char > s;    while(gets(a))    {        s.clear();        int flag=1;        l=strlen(a);        if(l%3!=0||l<3)            flag=0;        else        {            char b;            for(i=0; i<l; i++)            {                s.insert(a[i]);            }            if(s.size()!=3)                flag=0;            c=l/3;            for(i=0; i<l;)            {                b=a[i];                for(j=0; j<c; j++)               {                   if(a[i]!=b)                        flag=0;                i++;               }            }        }        if(flag==0)            printf("NO\n");        else            printf("YES\n");    }    return 0;}


0 0