CF960A.Check the string

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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).

A 有一个由若干个小写英文字母 'a' 组成的字符串。他将该字符串交给他的朋友 B,B 在该字符串末尾添加若干个字母 'b'。由于 A 和 B 都喜欢字符 'a' 和 'b',因此此时字符串中至少包含一个 'a' 和一个 'b'。

接着,B 将该字符串交给 C,C 在字符串末尾添加若干个字母 'c'。然而,由于 C 是 A 和 B 的好朋友,他所添加的字母 'c' 的数量等于字符串中 'a' 的数量,或者等于 'b' 的数量(或者同时等于两者)。

你手中有一个字符串,需要判断它是否可能通过上述方式得到。如果可能,输出 "YES";否则,输出 "NO"(不带引号)。

输入格式

The first and only line consists of a string SS ($ 1 \le |S| \le 5,000 $). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'.

第一行且唯一一行包含一个字符串 SS($ 1 \le |S| \le 5,000 $)。保证该字符串仅由小写英文字母 'a'、'b'、'c' 组成。

输出格式

Print "YES" or "NO", according to the condition.

根据条件输出 “YES” 或 “NO”。

输入输出样例

  • 输入#1

    aaabccc

    输出#1

    YES
  • 输入#2

    bbacc

    输出#2

    NO
  • 输入#3

    aabc

    输出#3

    YES

说明/提示

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'.

先考虑第一个例子:“c”的数量等于“a”的数量。

再考虑第二个例子:尽管“c”的数量等于“b”的数量,但顺序不正确。

最后考虑第三个例子:“c”的数量等于“b”的数量。

输入解题思路,AI测评打分。不知道怎么写?

首页