大佬看看为什么结果 Unaccepted

P1042 [NOIP2003 普及组] 乒乓球

zwt2037152465 @ 2024-10-09 20:03:14

#include <stdio.h>
#include<string.h>
#define MAX_SIZE 3000
int result1(char ch[],int n)
{
    int count1=0,count2=0,i=0,num=0;
    int score[100];
    while(i<n){
        count1=0,count2=0;
        while(count1<11&&count2<11&&i<n)
        {
            if(ch[i]=='W')
            count1++;
            else if(ch[i]=='L')
            count2++;
            i++;
        }
        score[num]=count1,score[num+1]=count2;
        num+=2;
    }
    for(int j=0;j<num;j+=2)
    {
        printf("%d : %d\n",score[j],score[j+1]);
    }
}
void result2(char ch[],int n)
{
    int count1=0,count2=0,i=0,num=0;
    int score[100];
    while(i<n){
        count1=0,count2=0;
        while(count1<21&&count2<21&&i<n)
        {
            if(ch[i]=='W')
            count1++;
            else if(ch[i]=='L')
            count2++;
            i++;
        }
        score[num]=count1,score[num+1]=count2;
        num+=2;
    }
    for(int j=0;j<num;j+=2)
    {
        printf("%d : %d\n",score[j],score[j+1]);
    }
}
int main() {
    char input[MAX_SIZE];
    int index = 0;
    char c;

    while (1) {
        c = getchar();
        if (c == 'E') {
            break;
        }
        if (c == '\n') {
            continue;
        }

        input[index] = c;
        index++;
        if (index >= MAX_SIZE - 1) {
            printf("数组已满,无法继续添加字符\n");
            break;
        }
    }
    input[index] = '\0'; 
    result1(input,strlen(input));
    printf("\n");
    result2(input,strlen(input));
    return 0;
}

by Civilight_Eterna @ 2024-10-09 20:05:45

你先把样例过了再说


by Civilight_Eterna @ 2024-10-09 20:06:57

读入的换行符不一定是\n,也可能是\r


by Civilight_Eterna @ 2024-10-09 20:07:30

最后还会有EOF


by Civilight_Eterna @ 2024-10-09 20:09:18

输出的空格去掉


by Civilight_Eterna @ 2024-10-09 20:11:22

result1没有返回值 int改为void @zwt2037152465


|