算法刷题记录:乒乓球
题目链接
https://ac.nowcoder.com/acm/contest/19306/1033
题目分析
这题好坑,乒乓球的比分如果相差<2
,还得继续比下去,但是题目里面没有说qwq。
看了眼题解才发现这个点。
AC代码
#include <iostream>
using namespace std;
// 统计11分制和21分制的比分
string s;
int main()
{
char t;
while (cin >> t) s += t;
int a = 0, b = 0, flag = false;
for (int i = 0; i < s.size() && s[i] != 'E'; ++ i)
{
if (s[i] == 'W') ++ a;
if (s[i] == 'L') ++ b;
if (a == 11 || b == 11 || flag)
{
flag = true;
if (abs(a - b) >= 2)
{
cout << a << ':' << b << endl;
flag = false;
a = 0, b = 0;
}
}
}
cout << a << ':' << b << endl;
a = 0, b = 0;
cout << endl;
flag = false;
for (int i = 0; i < s.size() && s[i] != 'E'; ++ i)
{
if (s[i] == 'W') ++ a;
if (s[i] == 'L') ++ b;
if (a == 21 || b == 21 || flag)
{
flag = true;
if (abs(a - b) >= 2)
{
cout << a << ':' << b << endl;
flag = false;
a = 0, b = 0;
}
}
}
cout << a << ':' << b << endl;
}
本文来自博客园,作者:想个昵称好难ABCD,转载请注明原文链接:https://www.cnblogs.com/ClockParadox43/p/17438724.html