【cfA】check the string

/*
http://codeforces.com/contest/960/problem/A

outputstandard output
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
inputCopy
aaabccc
output
YES
inputCopy
bbacc
output
NO
inputCopy
aabc
output
YES
*/

#include<iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include<map>
#include<algorithm>
using namespace std;
char store[5500];
int len,i,j,k;

map<char,int>mmap;
int judge ()
{
    len = strlen(store);//只能用于字符串,不包括\0
    for (i=0; i<len; i++)
        if(store[i]<store[i-1])return 0;
            mmap[store[i]]++;
    if (mmap['a']==0||mmap['b']==0||mmap['c']==0)
        return 0;
    if (mmap['a']==mmap['c']||mmap['c']==mmap['b'])
        return 1;
    else return 0;
}

int main ()
{
    while (~scanf("%s",store))
    {
        printf(judge()?"YES\n":"NO\n");
    }
    return 0;
}

/*注意细节
如果使用纯粹的逻辑写法 更加容易出问题
函数的返回值一定要有收束(保持逻辑严密)

map是一种自定义下标的数组

*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值