ChengSinuo @ 2024-10-08 22:36:10
完整代码```cpp
using namespace std;
int score[25 * 2501 + 5];
int main() { int n = 0; char a; while (scanf("%c", &a)) { if (a == 'E')break; if (a == '\n')continue; if (a == 'W')score[n++] = 1; else score[n++] = 2; } int w = 0, l = 0; for (int i = 0; i < n; i++) { if (score[i] == 1)w++; else l++; if (max(w, l) >= 11 && abs(w - l) >= 2) { cout << w << ':' << l << endl; w = 0; l = 0; } }; if (!(max(w, l) >= 11 && abs(w - l) >= 2))cout << w << ':' << l << endl; w = 0; l = 0; cout << endl; for (int i = 0; i < n; i++) { if (score[i] == 1)w++; else l++; if (max(w, l) >= 21 && abs(w - l) >= 2) { cout << w << ':' << l << endl; w = 0; l = 0; } } if (!(max(w, l) >= 21 && abs(w - l) >= 2))cout << w << ':' << l << endl; return 0; }
本地环境:msvc14/TDM GCC 9.2
OJ:QDUOJ
by ChengSinuo @ 2024-10-08 22:36:40
#include <bits/stdc++.h>
using namespace std;
int score[25 * 2501 + 5];
int main() {
int n = 0;
char a;
while (scanf("%c", &a)) {
if (a == 'E')break;
if (a == '\n')continue;
if (a == 'W')score[n++] = 1;
else score[n++] = 2;
}
int w = 0, l = 0;
for (int i = 0; i < n; i++) {
if (score[i] == 1)w++;
else l++;
if (max(w, l) >= 11 && abs(w - l) >= 2) {
cout << w << ':' << l << endl;
w = 0;
l = 0;
}
};
if (!(max(w, l) >= 11 && abs(w - l) >= 2))cout << w << ':' << l << endl;
w = 0;
l = 0;
cout << endl;
for (int i = 0; i < n; i++) {
if (score[i] == 1)w++;
else l++;
if (max(w, l) >= 21 && abs(w - l) >= 2) {
cout << w << ':' << l << endl;
w = 0;
l = 0;
}
}
if (!(max(w, l) >= 21 && abs(w - l) >= 2))cout << w << ':' << l << endl;
return 0;
}