luogu-p1042乒乓球-模拟

  看了一年前写得半死费了大半天才过的水题,(那时候特别菜)以及当时的代码,我$;TM;$怎么写出那么愚蠢的东西,重写此题,扔这里。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int cntw, cntl;

int (int st)
{
if ((cntw >= st || cntl >= st) && fabs(cntw - cntl) >= 2) return cntw > cntl ? 1 : 2;
return 0;
}

void work(string& str, int st)
{
cntw = cntl = 0;
for (unsigned i = 0; i < str.length(); i++)
{
if (str[i] == 'E') break;
if (str[i] == 'W') cntw++;
else if (str[i] == 'L') cntl++;
if (check(st) != 0)
{
cout << cntw << ':' << cntl << endl;
cntw = cntl = 0;
}
}
cout << cntw << ':' << cntl << endl << endl;
}

int main()
{
string str, in;
while (getline(cin, in)) str += in;
work(str, 11);
work(str, 21);
}