【NOIP2003】【luogu1042】乒乓球

problem

solution

codes

#include<iostream>
#include<string>
using namespace std;
int main(){
    string s, ss;
    while(cin>>ss)s += ss;
    int a = 0, b = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i]=='E')break;
        if(s[i]=='W')a++;else b++;
        if((a>=11&&a-b>=2) || (b>=11&&b-a>=2)){
            cout<<a<<":"<<b<<"
";
            a = b = 0;
        }
    }
    cout<<a<<":"<<b<<"

";
    //I am here.
    a = b = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i]=='E')break;
        if(s[i]=='W')a++;else b++;
        if((a>=21&&a-b>=2) || (b>=21&&b-a>=2)){
            cout<<a<<":"<<b<<"
";
            a = b = 0;
        }
    }
    cout<<a<<":"<<b<<"
";
    return 0;
}
原文地址:https://www.cnblogs.com/gwj1314/p/9444830.html