#include<iostream>
#include<vector>
#include <string>
#include<algorithm>
using namespace std;
struct stu
{
string idcard;
int descore;
int caiscore;
};
bool operator<(const stu& a, const stu& b)//总分降序排序,德才分降序
{
if (a.caiscore + a.descore > b.caiscore + b.descore)
return true;
else if (a.caiscore + a.descore == b.caiscore + b.descore && a.descore > b.descore)
return true;
else if (a.caiscore + a.descore == b.caiscore + b.descore && a.descore == b.descore && a.idcard < b.idcard)
return true;
else
return false;
}
int main()
{
int stunum;
int lscore;
int priorscore;
cin >> stunum >> lscore >> priorscore;
vector<stu> v;
stu student;
for (int i = 0; i < stunum; i++)
{
cin >> student.idcard >> student.descore >> student.caiscore;
v.push_back(student);
}
vector<stu> v1;
for (int j = 0; j < stunum; j++)
{
if (v[j].descore >= lscore && v[j].caiscore >= lscore)
v1.push_back(v[j]);
}
vector<stu> first;
vector<stu> second;
vector<stu> third;
vector<stu> fourth;
for (int t = 0; t < v1.size(); t++)
{
if (v1[t].descore >= priorscore && v1[t].caiscore >= priorscore)
{
first.push_back(v1[t]);
}
else if (v1[t].descore >= priorscore && v1[t].caiscore < priorscore)
second.push_back(v1[t]);
else if(v1[t].descore < priorscore && v1[t].caiscore < priorscore&& v1[t].descore >= v1[t].caiscore)
third.push_back(v1[t]);
else
fourth.push_back(v1[t]);
}
sort(first.begin(), first.end());
sort(second.begin(), second.end());
sort(third.begin(), third.end());
sort(fourth.begin(), fourth.end());
fourth.insert(fourth.begin(), third.begin(), third.end());
fourth.insert(fourth.begin(), second.begin(), second.end());
fourth.insert(fourth.begin(), first.begin(), first.end());
cout << v1.size() << endl;
for (int i = 0; i < fourth.size(); i++)
{
cout << fourth[i].idcard << " " << fourth[i].descore << " " << fourth[i].caiscore << endl;
}
}
需要注意的地方有:
sort()函数有两个版本。第一个版本:
sort(books.begin(),books.end())
它的函数原型为:
bool operator<();
另外一个版本是:sort(books.begin(),books.end(),comp)
函数原型为 bool comp();