题解 | 最厉害的学生

最厉害的学生

https://www.nowcoder.com/practice/b6e7a9ca04d8418b805b3b4b7d25b4d4

#include <iostream>
#include <string>
using namespace std;
struct Student{
    string name;
    int c1, c2, c3;
    int total;
};
int main() {
    int N;
    cin >> N; // 注意 while 处理多个 case
    Student student [1000];
    int max_total = -1;
    int index = 0;
    for(int i = 0; i < N; i++){
        cin >> student[i].name >> student[i].c1 >> student[i].c2 >> student[i].c3;
        student[i].total = student[i].c1 + student[i].c2 +student[i].c3;
        if(student[i].total > max_total){
            max_total = student[i].total;
            index = i;
        }
    }
    cout << student[index].name << " " << student[index].c1 << " " << student[index].c2 << " " << student[index].c3 << endl;
    return 0;
}
// 64 位输出请用 printf("%lld")

注意 空格和注意struct格式

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务