前言
今天是第15题 德才论
终于填坑
上题
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct Student {
int id, de, cai;
};
/* 重写cmp函数 */
bool cmp( Student a, Student b ) {
if( (a.de + a.cai) != (b.de + b.cai) )
return (a.de + a.cai) > (b.de + b.cai);
else if( a.de != b.de )
return a.de > b.de;
else
return a.id < b.id;
}
int main() {
int N, L, H; //N:考生总数 L:录取最低分数线 H:优先录取线
cin >> N >> L >> H;
vector<Student> v[4]; //vector<Student>型的大小为4的数组,每个元素又是一个vector
Student tmp;
int total = N; //实际录取人数
for( int i = 0; i < N; i++ ) {
cin >> tmp.id >> tmp.de >> tmp.cai;
if( tmp.de < L || tmp.cai < L )
total--;
else if( tmp.de >= H && tmp.cai >= H )
v[0].push_back(tmp); //第一类
else if( tmp.de >= H && tmp.cai < H )
v[1].push_back(tmp); //第二类
else if( tmp.de < H && tmp.cai < H && tmp.de >= tmp.cai )
v[2].push_back(tmp); //第三类
else
v[3].push_back(tmp); //第四类
}
cout << total << endl;
for( int i = 0; i < 4; i++ ) {
sort( v[i].begin(), v[i].end(), cmp );
for( int j = 0; j < v[i].size(); j++)
cout << v[i][j].id << " " << v[i][j].de << " " << v[i][j].cai << endl;
}
return 0;
}
这题很适合用vector,于是我终于去填坑了
finally
一点话说
追剧~