题解 | 乒乓球

乒乓球

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")

全部评论

相关推荐

XingHaozhe:没啥大问题啊,Agent + 后端业务,勇敢投!
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务