DALAO们40分求改!!!

P1042 [NOIP2003 普及组] 乒乓球

Galaxy2aa @ 2024-08-09 15:49:07

#include <bits/stdc++.h>
using namespace std;
char a[62505];
int main () {
    int len=0;
    while (a[len] != 'E') {
        cin >> a[++len];
    }
    if(a[1] == 'E') {
        cout << "0:0" << endl;
        cout << endl << "0:0";
        return 0;
    }

    int cnt=0;
    int w=0, l=0;

    // 11 分制
    for(int i=1; i<=len-1; i++) {
        if(a[i] == 'W') {
            ++ cnt;
            w ++;
        } else if(a[i] == 'L') {
            ++ cnt;
            l ++;
        }
        if(cnt == 11 || i == len-1) {
            cout << w << ":" << l << endl;
            w = 0, l = 0, cnt = 0;
        }
    }
    w = 0;
    l = 0;
    cnt = 0;

    // 21 分制
    cout << endl;
    for(int i=1; i<=len-1; i++) {
        if(a[i] == 'W') {
            ++ cnt;
            w ++;
        } else if(a[i] == 'L') {
            ++ cnt;
            l ++;
        }
        if(cnt == 21 || i == len-1) {
            cout << w << ":" << l << endl;
            w = 0, l = 0, cnt = 0;
        }
    }
    return 0;
}

by are_you_clever @ 2024-08-10 11:48:29

虽然有点看不懂,但还是试试我的代码吧

#include<bits/stdc++.h>
using namespace std; 
int main(){
    string s;
    char a;
    for(;cin>>a && a!='E';)s+=a;

    int w=0,l=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='W')w++;
        else if(s[i]=='L')l++;
        if(w-l>=2 || l-w>=2)
        {
            if(w>=11 || l>=11)
            {
                cout<<w<<":"<<l<<endl;
                w=0;
                l=0;
            }
        }
    }
    cout<<w<<":"<<l<<endl<<endl;
    w=0;
    l=0;

    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='W')w++;
        else if(s[i]=='L')l++;
        if(w-l>=2 || l-w>=2)
        {
            if(w>=21 || l>=21)
            {
                cout<<w<<":"<<l<<endl;
                w=0;
                l=0;
            }
        }
    }
    cout<<w<<":"<<l;
    return 0;
} 

有亿点点长


by Galaxy2aa @ 2024-08-23 11:36:24

栓Q


|