题解 | 乒乓球
乒乓球
https://www.nowcoder.com/practice/78660925b1cd49b6b2e43cb375ed7945
#include <iostream>
using namespace std;
int main() {
string result;
cin>>result;
int refreshrounds = 0;
int W=0,L=0;
for(int i = 0;i<result.size();i++)
{
refreshrounds++;
if(result[i] == 'W')
{
W++;
}else {
L++;
}
if(i==result.size()-1)
{
cout<<W<<":"<<L<<endl;
if((W>=11||L>=11)&&abs(W-L)>1) cout<<0<<":"<<0<<endl;
continue;
}
if((W>=11||L>=11)&&abs(W-L)>1)
{
cout<<W<<":"<<L<<endl;
W=L=0;
refreshrounds = 0;
}
}
cout<<endl;
refreshrounds = 0;
W=0,L=0;
for(int i = 0;i<result.size();i++)
{
refreshrounds++;
if(result[i] == 'W')
{
W++;
}else {
L++;
}
if(i==result.size()-1)
{
cout<<W<<":"<<L<<endl;
if((W>=21||L>=21)&&abs(W-L)>1) cout<<0<<":"<<0<<endl;
continue;
}
if((W>=21||L>=21)&&abs(W-L)>1)
{
cout<<W<<":"<<L<<endl;
W=L=0;
refreshrounds = 0;
}
}
}
// 64 位输出请用 printf("%lld")
