30pts,求调!!!

P1042 [NOIP2003 普及组] 乒乓球

DESTRUCTION_WA @ 2024-10-09 12:53:13

#include <bits/stdc++.h>
using namespace std;
int main() {

    char ch;
    string str = "";
    int w = 0,l = 0,a = 0,b = 0;
    while(cin >> ch){
        if(ch == 'E'){
            break;
        }
        if(ch == 'W'){
            w++;
            str += "W";
        }else{
            l++;
            str += "L";
        }
        if(w == 11 || l == 11){
            cout << w << ":" << l << endl;
            w = 0;
            l = 0;
        }
    }
    if(w != 0 || l != 0){
        cout << w << ":" << l << endl << endl;
    }else{
        cout << endl;
    }
    int i = 0;
    while(1){
        if(str[i] == 'W'){
            a++;
        }else{
            b++;
        }
        if(a == 21 || b == 21){
            cout << a << ":" << b << endl;
            a = 0;
            b = 0;
        }
        if(i == str.size()-1){
            break;
        }
        i++;
    }
    cout << a << ":" << b;

    return 0;
}

#1 RE
#2-5,9-10 WA
#6-8 AC

是的可能码风有亿点怪


by BNCDBD @ 2024-10-09 20:45:41

@bored_frank

直到分差大于或者等于2,才一局结束。

是不是没判断


by DESTRUCTION_WA @ 2024-10-10 12:19:27

@BNCDBD 可是现在变成了10pts

#include <bits/stdc++.h>
using namespace std;
int main() {

    char ch;
    string str = "";
    int w = 0,l = 0,a = 0,b = 0;
    while(cin >> ch){
        if(ch == 'E'){
            break;
        }
        if(ch == 'W'){
            w++;
            str += "W";
        }else{
            l++;
            str += "L";
        }
        if(w - l >= 2 || l - w >= 2){
            if(w >= 11 || l >= 11){
                cout << w << ":" << l << endl;
                w = 0;
                l = 0;
            }
        }
    }
    if(w != 0 || l != 0){
        cout << w << ":" << l << endl << endl;
    }else{
        cout << endl;
    }
    int i = 0;
    while(1){
        if(str[i] == 'W'){
            a++;
        }else{
            b++;
        }
        if(a - b >= 2 || b - a >= 2){
            if(a >= 11 || b >= 11){
                cout << a << ":" << b << endl;
                a = 0;
                b = 0;
            }
        }
        if(i == str.size()-1){
            break;
        }
        i++;
    }
    cout << a << ":" << b;

    return 0;
}

by BNCDBD @ 2024-10-10 20:55:38

@bored_frank 可以看看我的

#include<bits/stdc++.h>

using namespace std;
char t[100005];
int cnt;
int main(){
    char c;
    while(c=getchar(),c!='E'){
        if(c=='W'||c=='L'){
            t[cnt++]=c;
        }
    }
    int w=0,l=0;
    for(int i=0;i<cnt;++i){
        if(t[i]=='W'){
            w++;
        }else if(t[i]=='L'){
            l++;
        }
        if((w>=11||l>=11)&&abs(w-l)>=2){
            printf("%d:%d\n",w,l);
            w=0,l=0;
        }
    }
    printf("%d:%d\n\n",w,l);
    w=0,l=0;
    for(int i=0;i<cnt;++i){
        if(t[i]=='W'){
            w++;
        }else if(t[i]=='L'){
            l++;
        }
        if((w>=21||l>=21)&&abs(w-l)>=2){
            printf("%d:%d\n",w,l);
            w=0,l=0;
        }
    }
    printf("%d:%d",w,l);
    return 0;
}

|