• Check the string


    A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.

    B now gives this string to C and he appends some number of letters 'c' to the end of the string. However, since C is a good friend of A and B, the number of letters 'c' he appends is equal to the number of 'a' or to the number of 'b' in the string. It is also possible that the number of letters 'c' equals both to the number of letters 'a' and to the number of letters 'b' at the same time.

    You have a string in your hands, and you want to check if it is possible to obtain the string in this way or not. If it is possible to obtain the string, print "YES", otherwise print "NO" (without the quotes).

    Input

    The first and only line consists of a string SS (1|S|5000). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'.

    Output

    Print "YES" or "NO", according to the condition.

    Examples
    input
    aaabccc
    output
    YES
    input
    bbacc
    output
    NO
    input
    aabc
    output
    YES
    Note

    Consider first example: the number of 'c' is equal to the number of 'a'.

    Consider second example: although the number of 'c' is equal to the number of the 'b', the order is not correct.

    Consider third example: the number of 'c' is equal to the number of 'b'.

     

     

     1 #include <stdio.h>
     2 #include <string.h>
     3 int main()
     4 {
     5     int a,b,c,flag0,flag1,flag2,flag,i,len;
     6     char s[5001];
     7     gets(s);
     8     len=strlen(s);
     9     a=0;
    10     b=0;
    11     c=0;
    12     flag0=0;
    13     flag1=0;
    14     flag2=0;
    15     flag=0;
    16     len=strlen(s);
    17     for(i=0; i<len; i++)
    18     {
    19         if(s[i]=='a')
    20         {
    21             if(flag1||flag2)
    22             {
    23                 printf("NO
    ");
    24                 return 0;
    25             }
    26             a++;
    27             flag0=1;
    28         }
    29         else if(s[i]=='b')
    30         {
    31             if(!flag0||flag2)
    32             {
    33                 flag=1;
    34                 break;
    35             }
    36             b++;
    37             flag1=1;
    38         }
    39         else if(s[i]=='c')
    40         {
    41             if(!flag0||!flag1)
    42             {
    43                 flag=1;
    44                 break;
    45             }
    46             c++;
    47             flag2=1;
    48         }
    49     }
    50     if(flag==1)
    51         printf("NO
    ");
    52     else if((c==a||c==b)&&(c!=0&&b!=0))///注意要防止出现只有a,没有其他字母的情况
    53         printf("YES
    ");
    54     else
    55         printf("NO
    ");
    56     return 0;
    57 }
  • 相关阅读:
    朴英敏: 用crash工具分析Linux内核死锁的一次实战【转】
    ext3,ext4,xfs和btrfs文件系统性能对比【转】
    STM32MP157——Remoteproc和RPMsg【转】
    使用edac工具来检测服务器内存故障.【转】
    面试题-python 什么是生成器(generator)?
    面试题-python 什么是迭代器(Iterator)?
    面试题-python 浅拷贝和深拷贝(copy模块)
    selenium+python自动化104-如何获取隐藏元素text文本
    面试题-websocket 接口如何测试?
    jmeter压测学习47-发soap请求测试webservice接口
  • 原文地址:https://www.cnblogs.com/wkfvawl/p/9215418.html
Copyright © 2020-2023  润新知