题目链接
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;
}
标签:11,题目,int,flag,乒乓球,++,算法,刷题
From: https://www.cnblogs.com/ClockParadox43/p/17438724.html