ACM 训练日志记录 · 思考 · 成长 提交 / 修改记录
王梓豪 / 题目列表训练档案
导出

P1042 乒乓球

来源:洛谷 ★ 1000

本题活力0.26按难度、完成结果与训练证据估算

算法如山行则将至

题目描述

给定一系列W(华华得分)和L(对手得分)的比赛记录,分别按11分制和21分制计算每局比分,直到分差≥2才结束一局。

代码

#include <bits/stdc++.h>
using namespace std;
int main()
{
    char a;
    string s,temp;
    while(cin>>temp)
    {
        s+=temp;
    }
    
    int x11=0,y11=0;
    int x21=0,y21=0;
    istringstream iss(s);
    while(iss>>a)
    {
        if(a=='W'){x11++;}
        if(a=='L'){y11++;}
        if(a=='E')break;
        if((x11>=11||y11>=11)&&(abs(x11-y11)>=2))
        {cout<<x11<<':'<<y11<<endl;x11=0;y11=0;}
    }
    cout<<x11<<':'<<y11<<endl<<endl;
    istringstream iss1(s);
    while(iss1>>a)
    {
        if(a=='W'){x21++;}
        if(a=='L'){y21++;}
        if(a=='E')break;
        if((x21>=21||y21>=21)&&(abs(x21-y21)>=2))
        {cout<<x21<<':'<<y21<<endl;x21=0;y21=0;}
        
    }
    cout<<x21<<':'<<y21<<endl;
}