[2018-4-8]BNUZ套题比赛div2 CodeForces 960A【补】
2018-04-09 16:03
399 查看
A. Check the stringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA 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).InputThe 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'.OutputPrint "YES" or "NO", according to the condition.ExamplesinputCopy
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");
}
aaabcccoutput
YESinputCopy
bbaccoutput
NOinputCopy
aabcoutput
YESNoteConsider 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");
}
相关文章推荐
- [2018-4-8]BNUZ套题比赛div2 CodeForces 960B【补】
- [2018-4-8]BNUZ套题比赛div2 CodeForces 934A【补】
- [2018-3-16]BNUZ套题比赛div2 CodeForces 869B【补】
- [2018-4-8]BNUZ套题比赛div2 CodeForces 934B【补】
- [2018-3-16]BNUZ套题比赛div2 CodeForces 892B【补】
- [2018-3-16]BNUZ套题比赛div2 【补题】
- [2017-3-17]BNUZ套题比赛div2 C - Anton and Fairy Tale
- [2017-3-17]BNUZ套题比赛div2 D - Gena's Code
- [2017-3-17]BNUZ套题比赛div2 E - Money Transfers
- CodeForces 569A 第六周比赛C踢
- 小比赛(CodeForces 339D,POJ 1321,HDU 5078,HDU 2795,HDU 1385,HDU 1671,HDU 2923,POJ 2349)
- CSU-ACM2017暑假集训比赛7 C - Pasha and Tea - CodeForces - 557B
- CodeForces 478B 第八次比赛 B题
- 关于codeforces比赛规则介绍(转载)
- CSU-ACM2017暑假集训比赛8 - B - The Two Routes - CodeForces - 601A
- CodeForces 673B Problems for Round(比赛出题规则)
- CodeForces比赛规则
- CodeForces 569A 第八次比赛 C题
- CSU-ACM2017暑假集训比赛3D - D CodeForces - 557C
- CSU-ACM2017暑假集训比赛8 - C - GCD Table - CodeForces - 582A