b9113fced86a32cad0d8 @ 2024-10-24 07:42:49
RT,最后一个点WA
#include<bits/stdc++.h>
using namespace std;
string s;
char c;
int a11,b11;
int a21,b21;
int main(){
while(true){
cin>>c;
if(c == 'E') break;
s += c;
}
int n = s.length();
if(n == 0){
cout<<"0:0\n\n0:0";
}
for(int i = 0;i < n;i++){
if(s[i] == 'W') a11++;
else b11++;
if(abs(a11 - b11) >= 2 && max(a11,b11) >= 11){
cout<<a11<<":"<<b11<<endl;
a11 = 0;
b11 = 0;
}
}
if(a11 != 0 || b11 != 0) cout<<a11<<":"<<b11<<endl;
cout<<endl;
for(int i = 0;i < n;i++){
if(s[i] == 'W') a21++;
else b21++;
if(abs(a21 - b21) >= 2 && max(a21,b21) >= 21){
cout<<a21<<":"<<b21<<endl;
a21 = 0;
b21 = 0;
}
}
if(a21 != 0 || b21 != 0) cout<<a21<<":"<<b21<<endl;
}
by WLOG404 @ 2024-12-04 22:59:36
题目说“当一局比赛结束后,下一局立刻开始”,以及“如果一局比赛刚开始,则此时比分为0:0”,说明0:0的情况要输出。
因此,不要特判0:0,直接输出剩余的比分就行了,另外你的代码中只输入“E”也不用特判了。
修改如下:
#include<bits/stdc++.h>
using namespace std;
string s;
char c;
int a11,b11;
int a21,b21;
int main(){
while(true){
cin>>c;
if(c == 'E') break;
s += c;
}
int n = s.length();
for(int i = 0;i < n;i++){
if(s[i] == 'W') a11++;
else b11++;
if(abs(a11 - b11) >= 2 && max(a11,b11) >= 11){
cout<<a11<<":"<<b11<<endl;
a11 = 0;
b11 = 0;
}
}
cout<<a11<<":"<<b11<<endl;
cout<<endl;
for(int i = 0;i < n;i++){
if(s[i] == 'W') a21++;
else b21++;
if(abs(a21 - b21) >= 2 && max(a21,b21) >= 21){
cout<<a21<<":"<<b21<<endl;
a21 = 0;
b21 = 0;
}
}
cout<<a21<<":"<<b21<<endl;
}