1055 The World's Richest

模拟一个福布斯分类排行榜。给N个人的名字,年龄,财富。
给K个筛选标准,包括M最大输出人数(最多100人),年龄范围。

之后按照:The outputs must be in non-increasing order of the net worths. In case there are equal worths, it must be in non-decreasing order of the ages. If both worths and ages are the same, then the output must be in non-decreasing alphabetical order of the names. It is guaranteed that there is no two persons share all the same of the three pieces of information. In case no one is found, output None.输出。

钱多的优先,年龄小的优先,名字字典序小的优先。

为什么vt[i].name没有&?
首先说明 %s格式符 表示用来输入出一个字符串 而字符串是以数组的形式的存储的
c语言中数组名代表该数组的起始地址。 此处,a为数组名 代表的是首地址,所以就不用取地址符了, 再用取地址符号 就重复了 请注意与%c的区别 理解就好啦。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

struct rich {
char name[10];
int age, money;
};

int cmp(rich a, rich b) {
if (a.money != b.money) {
return a.money > b.money;
} else if (a.age != b.age) {
return a.age < b.age;
} else {
return (strcmp(a.name, b.name) < 0);
}
}

int main() {
int n, k, num, amin, amax;
scanf("%d %d", &n, &k);
vector<rich> vt(n), v;
vector<int> book(205, 0);
for (int i = 0; i < n; i++) {
scanf("%s %d %d", vt[i].name, &vt[i].age, &vt[i].money);
}
sort(vt.begin(), vt.end(), cmp);
// 输入数据,排序
for (int i = 0; i < n; i++) {
if (book[vt[i].age] < 100) { // book[vt[i].age]为100说明有100个人了
v.push_back(vt[i]);
book[vt[i].age]++;
}
}
// 筛去每个年龄层100名后的人以及统计各年龄富豪人数
for (int i = 0; i < k; i++) {
scanf("%d %d %d", &num, &amin, &amax);
vector<rich> t;
for (int j = 0; j < v.size(); j++) {
if (v[j].age >= amin && v[j].age <= amax) {
t.push_back(v[j]);
}
}
// 符合要求的放入临时向量t
if (i != 0) printf("\n");
printf("Case #%d:", i + 1);
int flag = 0;
for (int j = 0; j < num && j < t.size(); j++) {
printf("\n%s %d %d", t[j].name, t[j].age, t[j].money);
flag = 1;
}
if (flag == 0) printf("\nNone");
}

return 0;

}

12 4
Zoe_Bill 35 2333
Bob_Volk 24 5888
Anny_Cin 95 999999
Williams 30 -22
Cindy 76 76000
Alice 18 88888
Joe_Mike 32 3222
Michael 5 300000
Rosemary 40 5888
Dobby 24 5888
Billy 24 5888
Nobody 5 0
4 15 45
4 30 35
4 5 95
1 45 50

Case #1:
Alice 18 88888
Billy 24 5888
Bob_Volk 24 5888
Dobby 24 5888
Case #2:
Joe_Mike 32 3222
Zoe_Bill 35 2333
Williams 30 -22
Case #3:
Anny_Cin 95 999999
Michael 5 300000
Alice 18 88888
Cindy 76 76000
Case #4:
None