社区讨论

90分求助,第一个测试点没过

P5740【深基7.例9】最厉害的学生参与者 2已保存回复 4

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
4 条
当前快照
1 份
快照标识符
@ludw8qnq
此快照首次捕获于
2024/03/30 17:32
2 年前
此快照最后确认于
2024/03/30 19:43
2 年前
查看原帖
CPP
#include<iostream>
#include<algorithm>
using namespace std;

struct Student{
    string name;
    int chinese;
    int math;
    int english;
};

bool cmp(const Student& s1, const Student& s2){
    if((s1.chinese+s1.math+s1.english) > (s2.chinese+s2.math+s2.english)){
    	return true;
	}else{
		return false;
	}
}

int n;
Student s[1000];

int main()
{
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> s[i].name >> s[i].chinese >> s[i].math >> s[i].english;
    }
    sort(s, s+n, cmp);
    cout << s[0].name << " " << s[0].chinese << " " << s[0].math << " " << s[0].english << endl;
    return 0;
}

回复

4 条回复,欢迎继续交流。

正在加载回复...