Check the string(cf 960A)

Description

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|50001≤|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.

Sample Input

aaabccc
Sample Output
YES
Sample Input
bbacc
Sample Output
NO
Sample Input
aabc
Sample Output
YES

题解:简单水题,竟然还在至少有一个a和b处wa了一发,惭愧!

代码如下:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define maxn 10001
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define eps 0.00000001
int main()
{
    char a[5555];
    cin>>a;
    int l=strlen(a),flag=0;
    int s1=0,s2=0,s3=0;
    for(int i=0;i<l-1;i++)
	{
		if(a[i]>a[i+1])
			flag=1;
		if(a[i]=='a')
			s1++;
		if(a[i]=='b')
			s2++;
		if(a[i]=='c')
			s3++;
	}
	if(a[l-1]=='a')
		s1++;
	if(a[l-1]=='b')
		s2++;
	if(a[l-1]=='c')
		s3++;
	if(flag==0&&(s1==s3||s2==s3)&&s1>0&&s2>0&&s3>0)
		printf("YES\n");
	else
		printf("NO\n");
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值