leiyuhan @ 2024-12-02 23:27:34
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<char> lines;
char ch;
cin >> ch;
int a = 0;
int b = 0;
while (1)
{
if (ch == 'E') break;
lines.push_back(ch);
cin >> ch;
}
for (char temp : lines)
{
if (temp == 'E') break;
else if (temp == 'W')
{
a++;
}
else if (temp == 'L')
{
b++;
}
if ((a == 11 || b == 11) && ( (a - b) >= 2 || (b - a) >= 2))
{
cout << a << ':' << b << endl;
a = 0;
b = 0;
}
else if ((a > 11 || b > 11) && ((a - b) > 2 || (b - a) > 2))
{
cout << a << ':' << b << endl;
a = 0;
b = 0;
}
}
cout << a << ':' << b << endl;
cout << endl;
a = 0;
b = 0;
for (char temp : lines)
{
if (temp == 'E') break;
else if (temp == 'W')
{
a++;
}
else if (temp == 'L')
{
b++;
}
if ((a == 21 || b == 21) && ((a - b) >= 2 || (b - a) >= 2))
{
cout << a << ':' << b << endl;
a = 0;
b = 0;
}
else if ((a > 21 || b > 21) && ((a - b) > 2 || (b - a) > 2))
{
cout << a << ':' << b << endl;
a = 0;
b = 0;
}
}
cout << a << ':' << b;
return 0;
}
by YBa2Cu3O7 @ 2024-12-03 00:42:24
感觉你判断的部分不太对,比赛的分制不是这个意思。提供一个相对简洁一点的写法。
#include <bits/stdc++.h>
using namespace std;
int main(){
char ch = 'w';
int sc1 = 0, sc2 = 0, mode = 0;
vector<char> v;
auto check = [&](int s) {
if (sc1 == s && sc2 == s) {
mode = 1;
return;
}
if (mode == 0) {
if (sc1 == s + 1 || sc2 == s + 1) {
cout << sc1 << ':' << sc2 << '\n';
sc1 = 0;
sc2 = 0;
mode = 0;
}
}
else {
if (sc1 > sc2 + 1 || sc2 > sc1 + 1) {
cout << sc1 << ':' << sc2 << '\n';
sc1 = 0;
sc2 = 0;
mode = 0;
}
}
};
while (ch != 'E') {
cin >> ch;
v.push_back(ch);
if (ch == 'W') {
sc1++;
}
else if(ch == 'L') {
sc2++;
}
check(10);
}
cout << sc1 << ':' << sc2 << '\n';
cout << '\n';
sc1 = 0, sc2 = 0, mode = 0;
for (int i = 0; i < v.size()-1; ++i) {
ch = v[i];
if (ch == 'W') {
sc1++;
}
else {
sc2++;
}
check(20);
}
cout << sc1 << ':' << sc2 << '\n';
}