玄关!!!(50pts)

P1042 [NOIP2003 普及组] 乒乓球

135791a @ 2024-08-06 12:44:15

#include<bits/stdc++.h>
using namespace std;
string s;
char a[1000005];
long long x=0;
int main(){
    while (cin>>s) {
        for (int i=0;i<s.size();i++) a[x++]=s[i];
    }
    long long s1=0,s2=0;
    for (int i=0;i<x;i++) {
        if (a[i]=='E') {
            cout<<s1<<":"<<s2<<endl;
            break;
        }
        if (a[i]=='W') s1++;
        if (a[i]=='L') s2++;
        if ((s1==11 || s2==11) && abs(s1-s2)>=2) {
            cout<<s1<<":"<<s2<<endl;
            s1=0;
            s2=0;
        }
    }
    cout<<endl;
    s1=0,s2=0;
    for (int i=0;i<x;i++) {
        if (a[i]=='E') {
            cout<<s1<<":"<<s2;
            break;
        }
        if (a[i]=='W') s1++;
        if (a[i]=='L') s2++;
        if ((s1==21 || s2==21) && abs(s1-s2)>=2) {
            cout<<s1<<":"<<s2<<endl;
            s1=0;
            s2=0;
        }
    }
    return 0;
}

by tangzirui1016 @ 2024-08-06 13:02:21

会不会两个人打成10:10或20:20,然后要加赛呢?


by __zjr__ @ 2024-08-06 19:03:49

@135791a 是这样的,要把s==11改成是s>=11,s==21改成s>=21。

现在A了。

#include<bits/stdc++.h>
using namespace std;
string s;
char a[1000005];
long long x=0;
int main(){
    while (cin>>s) {
        for (int i=0;i<s.size();i++) a[x++]=s[i];
    }
    long long s1=0,s2=0;
    for (int i=0;i<x;i++) {
        if (a[i]=='E') {
            cout<<s1<<":"<<s2<<endl;
            break;
        }
        if (a[i]=='W') s1++;
        if (a[i]=='L') s2++;
        if ((s1>=11 || s2>=11) && abs(s1-s2)>=2) {
            cout<<s1<<":"<<s2<<endl;
            s1=0;
            s2=0;
        }
    }
    cout<<endl;
    s1=0,s2=0;
    for (int i=0;i<x;i++) {
        if (a[i]=='E') {
            cout<<s1<<":"<<s2;
            break;
        }
        if (a[i]=='W') s1++;
        if (a[i]=='L') s2++;
        if ((s1>=21 || s2>=21) && abs(s1-s2)>=2) {
            cout<<s1<<":"<<s2<<endl;
            s1=0;
            s2=0;
        }
    }
    return 0;
}

|