PAT(A)1062 Talent and Virtue (25分)(sort()函数)
程序员文章站
2022-07-08 22:19:54
...
Sample Input
14 60 80
10000001 64 90
10000002 90 60
10000011 85 80
10000003 85 80
10000004 80 85
10000005 82 77
10000006 83 76
10000007 90 78
10000008 75 79
10000009 59 90
10000010 88 45
10000012 80 100
10000013 90 99
10000014 66 60
Sample Output
12
10000013 90 99
10000012 80 100
10000003 85 80
10000011 85 80
10000004 80 85
10000007 90 78
10000006 83 76
10000005 82 77
10000002 90 60
10000014 66 60
10000008 75 79
10000001 64 90
思路:
英文德才论,就是英文理解比较麻烦。
代码
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;
#define endl '\n'
typedef long long ll;
struct node {
string id;
int de;
int cai;
int sum;
int r;
}peo[100005];
bool cmp(node a, node b)
{
if (a.r != b.r)
return a.r < b.r;
if (a.sum != b.sum)
return a.sum > b.sum;
if (a.de != b.de)
return a.de > b.de;
return a.id < b.id;
}
int main()
{
int n, l, h;
cin >> n >> l >> h;
int num = 0;
string id;
int de, cai;
for (int i = 0; i < n; ++i)
{
cin >> id >> de >> cai;
if (de < l || cai < l) continue;
peo[num].id = id;
peo[num].de = de;
peo[num].cai = cai;
peo[num].sum = de + cai;
if (de >= h && cai >= h)
peo[num].r = 1;
else if (de >= h && cai < h)
peo[num].r = 2;
else if (de < h && de >= cai)
peo[num].r = 3;
else
peo[num].r = 4;
num++;
}
sort(peo, peo + num, cmp);
cout << num << endl;
for (int i = 0; i < num; ++i)
{
cout << peo[i].id << " " << peo[i].de << " " << peo[i].cai << endl;
}
return 0;
}