[2018-4-8]BNUZ套题比赛div2 CodeForces 960A Check the string【补】

A. Check the string
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard 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
input
Copy
aaabccc
output
YES
input
Copy
bbacc
output
NO
input
Copy
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'.

题意: 给个字符串(只包含abc),至少包含 1个a 和 1个b,当 a的数量 b的数量等于 c的数量 时,并且字符串时按abc顺序的 是 YES

题解:用 变量 a,b ,c 分别记录字符abc 的 个数;last 记录上个出现字符的ASCII码, 当前字符如果小于上个字符的ASCII码则 直接输出 NO

AC代码:

#include <bits/stdc++.h>

using namespace std;

int main() {
	string s;
	cin >> s;
	int a = 0, b = 0, c = 0, last = -1;
	for (char i: s) {
		if (i == 'a')
			a++;
		else if (i == 'b')
			b++;
		else
			c++;
		if (i < last) 
			goto no;
		last = i;
	}
	if (a != 0 && b != 0 && (a == c || b == c))
		puts("YES");
	else
no:		puts("NO");
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值