德与才
作者:
漆黑泽克斯原始型二
,
2023-04-16 13:19:12
,
所有人可见
,
阅读 201
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct Student {
//定义一个结构体,存放学生的学号,德分,才分,总分,类别
int id, virtue, talent, total, type;
};
bool cmp(Student a, Student b) {
if (a.type != b.type) {
return a.type < b.type; //类型不同 小的在前
} else if (a.total != b.total) {
return a.total > b.total; //类型相同总分不同 ,总分大的在前
} else if (a.virtue != b.virtue) {
return a.virtue > b.virtue; //总分相同 德分大的在前
} else {
return a.id < b.id; //否则学号小的在前
}
}
int main() {
int n, l, h;
cin >> n >> l >> h;
//vector存放考生信息
vector<Student> students;
for (int i = 0; i < n; i++) {
//循环中输入考生信息
int id, virtue, talent;
cin >> id >> virtue >> talent;
//总分
int total = virtue + talent;
//类别
int type = 0; //第0类即至少有一个没有达到及格分的考生
if (virtue >= h && talent >= h) {
type = 1; //德和才都大于h为第一类
} else if (virtue >= h && talent >= l) {
type = 2; //德大于h,才大于l为第二类
} else if (virtue >= talent && virtue >= l && talent >= l) {
type = 3; //德和才都小于h,大于l并且德大于才为第三类
} else if (virtue >= l && talent >= l) {
type = 4; //都大于l为第四类
}
//如果不是第零类,将该考生信息存放在vector容器中
if (type != 0) {
students.push_back({id, virtue, talent, total, type});
}
}//循环结束
//对vector容器内的数据按照cmp排序
sort(students.begin(), students.end(), cmp);
int m = students.size();
cout << m << endl;
for (int i = 0; i < m; i++) {
cout << students[i].id << " " << students[i].virtue << " " << students[i].talent << endl;
}
return 0;
}