本地测试通过,下载的数据测试也通过.但是提交全部RE

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

cjl2580 @ 2020-12-11 18:56:59

求大佬看看这是为啥

#include <stdio.h>
struct student{
    char name[9];
    int chinese,math,english,sum;
};

int main()
{
    struct student st[1000];
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%s %d %d %d", st[i].name, &st[i].chinese, &st[i].math, &st[i].english);
        st[i].sum=st[i].chinese+st[i].math+st[i].english;
    }
    int max=st[0].sum,index;
    for(int i=1;i<n;i++){
        if(st[i].sum>max) { max=st[i].sum;index=i;}
    }
    printf("%s %d %d %d", st[index].name, st[index].chinese, st[index].math, st[index].english);

    return 0;
}

by Baiwhiter @ 2020-12-11 19:14:05

翻看了一下,都是小错误

int main() { struct student st[1000]; int n; scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%s %d %d %d", st[i].name, &st[i].chinese, &st[i].math, &st[i].english); st[i].sum=st[i].chinese+st[i].math+st[i].english; } int max=0,index; for(int i=0;i<n;i++){ if(st[i].sum>max) { max=st[i].sum;index=i;} } printf("%s %d %d %d", st[index].name, st[index].chinese, st[index].math, st[index].english);

return 0;

}


by CGDGAD @ 2020-12-11 19:15:06

希望更展现的Markdown?使用丰富。


by cjl2580 @ 2020-12-11 20:32:42

@Baiwhiter 好的谢谢大佬


by Tianxn @ 2021-01-09 20:59:13

#include <iostream>
using namespace std;

int n, maxi, maxV; 
struct node {
    int a, b, c;
    char s[10];
}f[1005];

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> f[i].s >> f[i].a >> f[i].b >> f[i].c;
        int tmp = f[i].a + f[i].b + f[i].c;
        if (tmp > maxV) maxV = tmp, maxi = i;
    }
    cout << f[maxi].s << " " << f[maxi].a << " " << f[maxi].b << " " << f[maxi].c << endl;
    return 0;
} 

|