求助

P1042 [NOIP2003 普及组] 乒乓球

lyx1234567 @ 2024-08-06 11:36:31

求助 为什么只有20分```c

include "stdio.h"

include "string.h"

int main(){ char score[70000],c; int i=0,win=0,lose=0; while(1){ scanf("%c",&c); if(c=='\n'){ continue; }else if(c=='E'){ score[i++]=c; break; }else{ score[i++]=c; } } for(i=0;score[i]!='E';i++){ if(score[i]=='W'){ win++; }else{ lose++; } if(win-lose>=2 && win>=11 || lose-win>=2 && lose>=11){ printf("%d:%d\n",win,lose); win=0;lose=0; } } printf("%d:%d\n\n",win,lose);win=0;lose=0; for(i=0;score[i]!='E';i++){ if(score[i]=='W'){ win++; }else{ lose++; } if(win-lose>=2 && win>=21 || lose-win>=2 && lose>=21){ printf("%d:%d\n",win,lose); win=0;lose=0; } } printf("%d:%d\n",win,lose); return 0; }


by losti @ 2024-08-06 11:42:00

@lyx1234567 看不懂(码风


by lyx1234567 @ 2024-08-06 11:48:18

@losti

include "stdio.h"

include "string.h"

int main(){

char score[70000],c;

int i=0,win=0,lose=0;

while(1){

    scanf("%c",&c);
    if(c=='\n'){
        continue;
    }else if(c=='E'){
        score[i++]=c;
        break;
    }else{
        score[i++]=c;
    }
}
for(i=0;score[i]!='E';i++){
    if(score[i]=='W'){
        win++;
    }else{
        lose++;
    }
    if(win-lose>=2 && win>=11 || lose-win>=2 && lose>=11){
        printf("%d:%d\n",win,lose);
        win=0;lose=0;
    }
}
printf("%d:%d\n\n",win,lose);win=0;lose=0;
for(i=0;score[i]!='E';i++){
    if(score[i]=='W'){
        win++;
    }else{
        lose++;
    }
    if(win-lose>=2 && win>=21 || lose-win>=2 && lose>=21){
        printf("%d:%d\n",win,lose);
        win=0;lose=0;
    }
}
printf("%d:%d\n",win,lose);
return 0;

}


by lyx1234567 @ 2024-08-06 11:49:17

@losti 第一次发,感谢


by lyx1234567 @ 2024-08-06 11:52:00

看了一下题解dalao,思路完全一样,死活就是WA


by lyx1234567 @ 2024-08-06 14:05:15

@losti 改了以后AC100:


#include "stdio.h"
#include "string.h"
int main(){
    char score[70000],c;
    int i=0,win=0,lose=0;
    while(1){
        scanf("%c",&c);
        if(c=='\n'){
            continue;
        }else if(c=='E'){
            break;
        }else{
            score[i++]=c;
        }
    }
    for(int j=0;j<i;j++){
        if(score[j]=='W'){
            win++;
        }else if(score[j]=='L'){
            lose++;
        }
        if(win-lose>=2 && win>=11 || lose-win>=2 && lose>=11){
            printf("%d:%d\n",win,lose);
            win=0;
            lose=0;
        }
    }
    printf("%d:%d\n\n",win,lose);win=0;lose=0;
    for(int j=0;j<i;j++){
        if(score[j]=='W'){
            win++;
        }else if(score[j]=='L'){
            lose++;
        }
        if(win-lose>=2 && win>=21 || lose-win>=2 && lose>=21){
            printf("%d:%d\n",win,lose);
            win=0;
            lose=0;
        }
    }
    printf("%d:%d\n",win,lose);
    return 0;
}

by losti @ 2024-08-07 11:54:51

@lyx1234567 恭喜,昨天没时间,抱歉,没帮你调


by lyx1234567 @ 2024-08-07 15:20:57

@losti 没事,感谢


|