80分求教!!!

P1042 [NOIP2003 普及组] 乒乓球

Exuan_zyx @ 2024-09-02 16:43:47

#include<bits/stdc++.h>
using namespace std;

int main(){
    string s;
    char N;
    while(N != 'E')
    {
        cin >> N;
        s = s + N;
    }
    int Long = s.size() - 1;
    if(s[0] == 'E'){
        cout << 0  << ":" << 0 << endl;
        return 0;
    }
//  cout << s << endl;
    int a = 0,b = 0;
    int sum = 0;
    while(sum != Long )
    {
        while(a != 11 && b != 11)
        {
            if(s[sum] == 'E') break;
            else if(s[sum] == 'W') a++;
            else b++;
            sum++;
        }
        while(abs(a - b) < 2)
        {
            if(s[sum] == 'E') break;
            else if(s[sum] == 'W') a++;
            else b++;
            sum++;
        }
        cout << a << ":" << b << endl;
        a = 0,b = 0;
    }
    sum = 0;
    cout << endl;
    while(sum != Long )
    {
        while(a != 21 && b != 21)
        {
            if(s[sum] == 'E') break;
            else if(s[sum] == 'W') a++;
            else b++;
            sum++;
        }
        while(abs(a - b) < 2)
        {
            if(s[sum] == 'E') break;
            else if(s[sum] == 'W') a++;
            else b++;
            sum++;
        }
        cout << a << ":" << b << endl;
        a = 0,b = 0;
    }
    cout << endl;
    return 0;
}

by z__j__y @ 2024-09-03 21:39:19

E的特判没必要那么多吧

在输入的时候特判就好了吧


by zjck2 @ 2024-09-14 21:53:36

80,同问

#include<bits/stdc++.h>
using namespace std;
char s[62505];
int win11,win21;
int lose11,lose21;
int i=0;
int main(){
    char a=0;
    while(a!='E'){
        cin>>a;
        s[i]=a;
        if(s[i]=='W') win11++;
        else lose11++;
        if((win11>=11||lose11>=11)&abs(win11-lose11)>=2){
            cout<<win11<<':'<<lose11<<endl;
            win11=0;
            lose11=0;
        }
        i++;
    }
    if(win11!=0||lose11-1!=0) cout<<win11<<':'<<lose11-1<<endl<<endl;
    i=0;
    while(s[i]!='E'){
        if(s[i]=='W') win21++;
        else lose21++;
        if((win21>=21||lose21>=21)&abs(win21-lose21)>=2){
            cout<<win21<<':'<<lose21<<endl;
            win21=0;
            lose21=0;
        }
        i++;
    }
    if(win21!=0||lose21!=0) cout<<win21<<':'<<lose21;
    return 0;
}
/*
WWWWWWWWWWWWWWWWWWWW
WWLWE
*/

|