样例过了,第一个数据也是一样的,为什么全WA啊(爆哭

P5740 【深基7.例9】最厉害的学生

1132wang @ 2020-03-30 21:38:15

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<stdbool.h>
typedef struct score
{
    char name[10];
    int Chinese;
    int English;
    int math;
}Score;
int main()
{
    int n,i,j;
    int max=0;
    int count=0;
    Score a[1005]={{},0,0,0};
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
         getchar();
        for(j=0;j<10;j++)
        {
            scanf("%c",&a[i].name[j]);
            if(a[i].name[j]==' ')
            {
                a[i].name[j]='\0';
                break;
            }
        }
        scanf("%d%d%d",&a[i].Chinese,&a[i].math,&a[i].English);
        if(max<a[i].Chinese+a[i].math+a[i].English)
        {
            max=a[i].Chinese+a[i].math+a[i].English;
            count=i;
        }
    }
    printf("%s %d %d %d ",a[count].name,a[count].Chinese,a[count].math,a[count].English);
    return 0;
}

by songxiao @ 2020-03-30 21:43:37

这是啥意思:

Score a[1005]={{},0,0,0};


by HearTheWindSing @ 2020-03-30 21:43:57

@1132wang 样例过了不代表就一定AC


by HearTheWindSing @ 2020-03-30 21:45:18

@Gorilla 这句应该没问题


by songxiao @ 2020-03-30 21:45:37

@1132wang 样例没过,你开头多了空行,自己运行一下就知道


by songxiao @ 2020-03-30 21:46:33

cin不香吗?


by HearTheWindSing @ 2020-03-30 21:47:13

@1132wang 你不用输入name的时候一位一位输入,直接scanf("%s",...)完事,而且还贴心地帮你加上\0,多好


by 1132wang @ 2020-03-31 11:01:20

@Gorilla 我运行跟我下载的数据是一样的啊。。空行在哪里啊呜呜呜
Score那句是初始化
表示C++还没学,C的输入真的搞得我要吐。。有空去学了


by 1132wang @ 2020-03-31 11:03:25

@wangyxhaha 我开始用的%s,然后发现他把后面要的空格和数字也读了,不得已改成了%c。。


by songxiao @ 2020-03-31 11:06:35

@1132wang 应该可以用%s,我看看


by songxiao @ 2020-03-31 11:15:03

@1132wang 改成了%s


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<stdbool.h>
typedef struct score
{
    char name[10];
    int Chinese;
    int English;
    int math;
}Score;
int main()
{
    int n,i,j;
    int max=0;
    int count=0;
    Score a[1005]={{},0,0,0};
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%s",&a[i].name);
        scanf("%d%d%d",&a[i].Chinese,&a[i].math,&a[i].English);
        if(max<a[i].Chinese+a[i].math+a[i].English)
        {
            max=a[i].Chinese+a[i].math+a[i].English;
            count=i;
        }
    }
    printf("%s %d %d %d ",a[count].name,a[count].Chinese,a[count].math,a[count].English);
    return 0;
}

| 下一页