• Check the string CodeForces


    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 S (1 ≤ |S| ≤ 5 000). 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'.

    题析:字符串规则 ‘a' 'b'出现的次数都不能为0,必须按a b c顺序,’c'出现的次数要等于‘a'次数或者’b'的次数。上面就是条件!

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 
     4 int main() {
     5     string str;
     6     cin>>str;
     7     int a,b,c;
     8     int flag  = 1;
     9     a = 0;
    10     b = 0;
    11     c = 0;
    12     for(int i = 0; i <     str.length(); i++) {
    13         if(str[i] == 'a') a++;
    14         else if(str[i] == 'b') b++;
    15         else if(str[i] == 'c') c++;
    16         if( i>= 1 && str[i-1]>str[i]) flag = 0;
    17     }
    18     if( (a == c|| c == b) && flag && (a!=0&&b!=0))    cout<<"YES"<<endl;
    19     else     cout<<"NO"<<endl;
    20 
    21     return 0;
    22 }
  • 相关阅读:
    图像处理之基础---卷积及其快速算法的C++实现
    嵌入式c语言笔试
    逻辑题
    多媒体开发之---h264 图像参数级语义
    多媒体开发之---h264 取流解码实现
    多媒体开发之---live555 分析客户端
    多媒体开发之---如何确定slice_header slice_type 的位置
    图像处理之基础---很好的一个开源文档库
    多媒体开发之---h264 高度和宽度获取
    Flutter实战视频-移动电商-65.会员中心_订单区域UI布局
  • 原文地址:https://www.cnblogs.com/jj81/p/8747642.html
Copyright © 2020-2023  润新知