PAT 1015 德才论
作者:互联网
解题思路:这是一道排序题,我们可以先按照题目要求进行分类,在进行排序。
代码实现:
#include <iostream>
#include <algorithm>
using namespace std;
struct student
{
int number;
int de;
int cai;
int total;
int category;
};
bool cmp(student a, student b)
{
if(a.category != b.category)
return a.category < b.category;
if(a.total != b.total)
return a.total > b.total;
if(a.de != b.de)
return a.de > b.de;
if(a.number != b.number)
return a.number < b.number;
}
int main()
{
int n, l, h, k = 0;
cin >> n >> l >> h;
student stus[n];
for(int i = 0; i < n; i++)
{
cin >> stus[k].number >> stus[k].de >> stus[k].cai;
if(stus[k].de < l || stus[k].cai < l)
continue;
stus[k].total = stus[k].de + stus[k].cai;
if(stus[k].de >= h && stus[k].cai >= h)
stus[k].category = 1;
else if(stus[k].de >= h && stus[k].cai < h)
stus[k].category = 2;
else if(stus[k].de < h && stus[k].cai < h && stus[k].de >= stus[k].cai)
stus[k].category = 3;
else
stus[k].category = 4;
k++;
}
sort(stus,stus + k, cmp);
cout << k << endl;
for(int i = 0; i < k; i++)
cout << stus[i].number << " " << stus[i].de << " " << stus[i].cai << endl;
return 0;
}
标签:category,stus,PAT,int,德才,de,number,cai,1015 来源: https://blog.csdn.net/weixin_59196442/article/details/118022314