程序只会输出0,c++求助

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

Etic_HAO @ 2022-08-27 13:50:13

#include <bits/stdc++.h>
using namespace std;

int number,Chinese,Mathematics,English,Chinesemax,Mathematicsmax,Englishmax;
char name,namemax;

int main(){
    cin>>number;
    for(int i=1;i<=number;i++){
        cin>>name>>Chinese>>Mathematics>>English;
        if(Chinese+Mathematics+English>Chinesemax+Mathematicsmax+Englishmax){
            Chinesemax=Chinese;
            Mathematicsmax=Mathematics;
            Englishmax=English;
            namemax=name;
        }
    }
    cout<<namemax<<" "<<Chinesemax<<" "<<Mathematicsmax<<" "<<Englishmax;
}

by fengziyi @ 2022-08-27 13:57:51

@Etic_HAO

char name,namemax;

name要定义成string,这么写

string name,namemax;

by fengziyi @ 2022-08-27 13:58:38

闲话:这题目样例好臭(恼


by Etic_HAO @ 2022-08-27 14:12:10

@fengziyi 谢谢


by Etic_HAO @ 2022-08-27 14:18:23

@fengziyi 改后90分


by Accelessar @ 2022-08-27 14:54:35

@Etic_HAO hack 数据:

1
senpai 0 0 0

by Accelessar @ 2022-08-27 14:55:22

应该是合法的……吧?


by fengziyi @ 2022-08-27 16:01:12

@Etic_HAO 我是这么写的,仅供参考


by Etic_HAO @ 2022-08-28 11:40:10

谢谢各位大佬


|