【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<<"\n";
            a = b = 0;
        }
    }
    cout<<a<<":"<<b<<"\n\n";
    //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<<"\n";
            a = b = 0;
        }
    }
    cout<<a<<":"<<b<<"\n";
    return 0;
}
posted @ 2018-05-23 21:21  gwj1139177410  阅读(146)  评论(0编辑  收藏  举报
选择