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


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

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

     
     
abc bc
 

Sample Output

     
     
YES NO

分析:

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

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

数组:s=strlen(it)

字符串:s=it.length()


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值