正解1:
#include<bits/stdc++.h>
using namespace std;
char C;
string S;
int n,A,B;
void Work(int Lim)
{
for(char i:S)
{
if(i=='W')A++;
if(i=='L')B++;
if(max(A,B)>=Lim&&abs(A-B)>=2)
{
cout<<A<<":"<<B<<endl;
A=0,B=0;
}
}
printf("%d:%d\n\n",A,B);
A=B=0;
}
int main()
{
while(cin>>C)
{
if(C=='E')break;
S+=C;
}
Work(11),Work(21);
return 0;
}
正解2:
#include<bits/stdc++.h>
using namespace std;
char C;
string S;
int n,A,B;
int main()
{
while(cin>>C)
{
if(C=='E')break;
S+=C;
}
for(char i:S)
{
if(i=='W')A++;
if(i=='L')B++;
if(max(A,B)>=11&&abs(A-B)>=2)
{
cout<<A<<":"<<B<<endl;
A=0,B=0;
}
}
printf("%d:%d\n",A,B);
A=B=0;
puts("");
for(char i:S)
{
if(i=='W')A++;
if(i=='L')B++;
if(max(A,B)>=21&&abs(A-B)>=2)
{
cout<<A<<":"<<B<<endl;
A=0,B=0;
}
}
printf("%d:%d\n",A,B);
return 0;
}
错解:
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
void processGame(const string& records, int winScore) {
int hua = 0, opp = 0;
for (char c : records) {
if (c == 'W') hua++;
else if (c == 'L') opp++;
}
int main() {
string input, records;
while (getline(cin, input)) {
for (char c : input) {
if (c == 'E') goto end_input;
if (c == 'W' || c == 'L') records += c;
}
}
end_input:
}