20pts求助,本地测试正确

P1042 [NOIP2003 普及组] 乒乓球

npxx_ZZY @ 2024-07-26 18:29:37

代码:

#include<iostream>
using namespace std;
int sum[1000005],n,l;
char ch;
int main(){
//  freopen("ppq.in","r",stdin);
//  freopen("ppq.out","w",stdout);
    while(ch!='E'){
        cin>>ch;
        if(ch!='E')sum[++n]=sum[n-1]+(ch=='W');
    } 
    for(int i=0;i<=n;i++){
        if(max(sum[i]-sum[l],i-l-sum[i]+sum[l])>=11&&max(sum[i]-sum[l],i-l-sum[i]+sum[l])-2>=min(sum[i]-sum[l],i-l-sum[i]+sum[l])||i==n){
            cout<<sum[i]-sum[l]<<":"<<i-l-sum[i]+sum[l]<<"\n";
            l=i; 
        }
    } 
    l=0;
    cout<<"\n";
    for(int i=0;i<=n;i++){
            if(max(sum[i]-sum[l],i-l-sum[i]+sum[l])>=21&&max(sum[i]-sum[l],i-l-sum[i]+sum[l])-2>=min(sum[i]-sum[l],i-l-sum[i]+sum[l])||i==n){
            cout<<sum[i]-sum[l]<<":"<<i-l-sum[i]+sum[l]<<"\n";
            l=i; 
        } 
    }
    return 0;
}

|