Pit 1: there are several lines of input, but the information should be treated as a whole. For example, the score of the last game in the first row is 2:1, which is not the end of the match. This score should be inherited to the information in the second row for further processing.
Pit 2: the end of a game, if and only if one of the scores is greater than or equal to 11 and the difference between the scores of both sides is greater than or equal to 2. Note that this is table tennis common sense rather than OI common sense. The last sentence in the question mentioned this problem, but it is not obvious.
Pit 3: line break between two different fractional system outputs.
Pit 4: in the Windows environment, we can judge whether we have finished reading and write while (CIN > > s) directly. When running, first wrap the line, then press Ctrl+Z, and then wrap the line to get the result.
Other: pay attention to code details. I can finish it in about ten minutes after I clear my mind.
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> using namespace std; string s; int a[2000009],b[2000009]; //Array a records whether there is a minute in a sentence of Huahua, array b records Huahua's opponent int main() { int n=0; while(cin>>s) { for(int i=0;i<s.length();i++) if(s[i]=='E')break; else if(s[i]=='W')a[++n]=1; else b[++n]=1; //Here, n does not need to be cleared, but takes all inputs as a whole } int answ=0,ansl=0; for(int i=1;i<=n;i++) { if(a[i])answ++; if(b[i])ansl++; if(answ>=11||ansl>=11) { if(abs(answ-ansl)>=2) { cout<<answ<<':'<<ansl<<endl; answ=0,ansl=0; //Score zero at the end of a game } } } cout<<answ<<':'<<ansl<<endl; cout<<endl; //New line!!! answ=0,ansl=0; for(int i=1;i<=n;i++) { if(a[i])answ++; if(b[i])ansl++; if(answ>=21||ansl>=21) { if(abs(answ-ansl)>=2) { cout<<answ<<':'<<ansl<<endl; answ=0,ansl=0; } } } cout<<answ<<':'<<ansl<<endl; return 0; }