Strange Class

Strange Class

 
 Accepts: 519
 
 Submissions: 1749
 Time Limit: 2000/1000 MS (Java/Others)
 
 Memory Limit: 65536/65536 K (Java/Others)
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
abc
bc
Sample Output
YES
NO
 
   
 
   
    
    
问题描述
在Vivid的学校里,有一个奇怪的班级(SC).在SC里,这些学生的名字非常奇怪。他们的名字形式是这样的
      
      
       
       anbncn
      
      (a,b,c两两不相同。).例如,叫”abc”,”ddppqq”的学生是在SC里的,然而叫”aaa”,”ab”,”ddppqqq”的同学并不是在SC里的。
Vivid交了许多的朋友,他想知道他们之中哪些人是在SC里的。
输入描述
多组测试数据(大概
      
      
       
       10
      
      组),每一个数据在一行中给出一个字符串S,代表Vivid一个朋友的名字。
请处理到文件末尾。

[参数约定]

      
      
       
       1|S|10.
      
      
|S| 是指S的长度.
S 只包含小写字母.
输出描述
对于每一个数据,如果Vivid的朋友是SC里的,那么输出YES,否则输出NO。
输入样例
abc
bc
输出样例
YES
NO
<span style="font-size:24px;">思路:昨天交了几次就是wa了,仔细读读题,发现如果aabbaa的话,我当时就认为是sc了,实际不是,<span style="font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; line-height: 1.42857143; white-space: pre-wrap;">所以还要再判断存储的字符是不是一样的。。控制一下。不用重新排序,就是直接按照题目给的顺序做。</span></span>
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
    char s[20],h[20];
    int len,i,a[20],k,g,count;
  while(cin>>s)
  {
      k=0;
      g=0;
     len=strlen(s);
     for(i=0;i<len;i++)  //aabbaa
     {
         count=1;
         while(i<len-1&&s[i]==s[i+1])
         {
              count++;
              i++;
         }
        a[k++]=count;
        h[g++]=s[i];
     }
     if(k==3 &&h[0]!=h[1] &&h[1]!=h[2] &&h[0]!=h[2] &&a[0]==a[1]&&a[0]==a[2]&&a[1]==a[2])
     {

         cout<<"YES"<<endl;
     }
     else
         cout<<"NO"<<endl;
  }
    return 0;
}
 
  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值