求...

P1042 [NOIP2003 普及组] 乒乓球

zcx20242024 @ 2024-10-06 09:46:35

#include<bits/stdc++.h>
using namespace std;
char a[750000];
int b[750000][3],c[750000][3];
int main()
{
    int n=1;
    while(cin>>a[n]&&a[n]!='E') n++;
    n--;
    int n1=1,n2=1;
    for(int i=1,j=1,k=1;i<=n;i++,j++,k++)
    {
        if(j==12) j=1,n1++;
        if(k==22) k=1,n2++;
        if(a[i]=='W') b[n1][1]++,c[n2][1]++;
        if(a[i]=='L') b[n1][2]++,c[n2][2]++;
    }
    for(int i=1;i<=n1;i++)
    {
        printf("%d:%d\n",b[i][1],b[i][2]);
    }
    cout<<endl;
    for(int i=1;i<=n2;i++)
    {
        if(i!=n2) printf("%d:%d\n",c[i][1],c[i][2]);
        else printf("%d:%d",c[i][1],c[i][2]);
    }
    return 0;
}

by kkksc_tbh @ 2024-10-06 11:35:51

#include<bits/stdc++.h>
#define int long long
using namespace std;
int win[62503];
int w,l;
char s;
signed main(){
    for(int i=1;cin>>s&&s!='E';i++){
        if(s=='W') win[i]=1;
        else win[i]=2;
    }
    for(int i=1;1;i++){
        if(win[i]==1) w++;
        if(win[i]==2) l++;
        if(win[i]==0){
            cout<<w<<':'<<l<<endl<<endl;
            break;
        }
        if(w-l>=2||l-w>=2){
            if(w>=11||l>=11){
                cout<<w<<':'<<l<<endl;
                w=0;
                l=0;
            }
        }
    }
    w=0;
    l=0;
    for(int i=1;1;i++){
        if(win[i]==1) w++;
        if(win[i]==2) l++;
        if(win[i]==0){
            cout<<w<<':'<<l;
            break;
        }
        if(w-l>=2||l-w>=2){
            if(w>=21||l>=21){
                cout<<w<<':'<<l<<endl;
                w=0;
                l=0;
            }
        }
    }
    return 0;
}

|