50分求调

P1042 [NOIP2003 普及组] 乒乓球

wuyuqi1028 @ 2024-08-16 10:03:03

大佬快帮帮我
#include<iostream>
using namespace std;
int main(){
    string a;
    int a1=0,a2=0;
    string a11="",a21="";
    while(getline(cin,a)&&a[0]!='E'){
        a11+=a;
        a21+=a;
    }
    for(int i=0;i<a11.size();i++){
        if(a11[i]=='W'){
            a1++;
        } else if(a11[i]=='L'){
            a2++;
        }
        if(a1==11||a2==11){
            cout<<a1<<':'<<a2<<'\n';
            a1=0;
            a2=0;
        }
    }
    cout<<a1<<':'<<a2<<'\n'<<'\n';
    a1=0;
    a2=0;
    for(int i=0;i<a21.size();i++){
        if(a21[i]=='W'){
            a1++;
        } else if(a21[i]=='L'){
            a2++;
        }
        if(a1==21||a2==21){
            cout<<a1<<':'<<a2<<'\n';
            a1=0;
            a2=0;
        }
    }
    cout<<a1<<':'<<a2<<'\n';
    return 0;
}

by qtswcy @ 2024-08-16 10:43:33

感谢


by qtswcy @ 2024-08-16 10:47:38

@wuyuqi1027


by aleavf @ 2024-08-17 16:02:55

@wuyuqi1027 分差超过两分才结束


by aleavf @ 2024-08-17 16:03:42

#include<bits/stdc++.h>
using namespace std;
long long c[100000],d[100000];
int main(){
    char x;
    long long y=0,o=0,a=0,b=0;
    while(x!='E'){
        cin>>x;
        if(x=='W'){
            c[o]++;
            a++;
        }
        if(x=='L'){
            b++;
            d[o]++;
        }
        if(x=='E'){
            cout<<a<<':'<<b<<endl;
            break;
        }
        if((a>=11||b>=11)&&(a-b>=2||b-a>=2)){
            cout<<a<<':'<<b<<endl;
            a=0;b=0;
        }
        if((c[o]>=21||d[o]>=21)&&(c[o]-d[o]>=2||d[o]-c[o]>=2)){
            o++;
        }   
    }
    cout<<endl;
    for(int i=0;i<=o;i++){
        cout<<c[i]<<':'<<d[i]<<endl;
    }   
}

by wuyuqi1028 @ 2024-08-19 10:54:23

@aleavf 谢谢大佬


|