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).
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'.
Print "YES" or "NO", according to the condition.
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;
}