求助大佬,谢谢!

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

LoserTao @ 2022-12-05 12:24:22

#include<stdio.h>
int main(){
    char a[1010][10]={'\0'};
    int b[1010][4]={0};
    int n,i,m,sum,max=-1,pot=0,len=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        getchar();
        m=1;
        sum=0;
        scanf("%c",&a[i][m]);
        while(a[i][m]!=' '){
            m=m+1;
            scanf("%c",&a[i][m]);
        }
        scanf("%d",&b[i][1]);
        scanf("%d",&b[i][2]);
        scanf("%d",&b[i][3]);
        sum=sum+b[i][1]+b[i][2]+b[i][3];
        if(sum>max){
            max=sum;pot=i;len=m-1;
        }
    }
    for(i=1;i<=len;i++){
        printf("%c",a[pot][i]);
    }
    printf(" %d %d %d",b[pot][1],b[pot][2],b[pot][3]);
    return 0;
}

样例和第一个测试点在自己的电脑上运行都没有问题,但上交后所有测试点都是WA,不知问题在哪,请求大佬帮助,谢谢!


by donnieguo @ 2022-12-05 13:34:38

C++爱莫能助啊…… 只能附上自己代码以示友好了

#include <iostream>
using namespace std;

string name[1001];
int ch[1001], ma[1001], en[1001];

int main() {
    int n, max_score = -1e9, num;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> name[i] >> ch[i] >> ma[i] >> en[i];
        if (ch[i] + ma[i] + en[i] > max_score) {
            max_score = ch[i] + ma[i] + en[i];
            num = i;
        }
    }
    cout << name[num] << ' ' << ch[num] << ' ' << ma[num] << ' ' << en[num];
    return 0;
}

by LoserTao @ 2022-12-05 15:24:21

@donnieguo 谢谢,已解决


|