-
Notifications
You must be signed in to change notification settings - Fork 0
/
1055.cpp
72 lines (61 loc) · 1.24 KB
/
1055.cpp
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
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
struct Info
{
char name[10];
int age;
int nworth;
};
bool cmp(const Info& in1, const Info& in2)
{
if (in1.nworth != in2.nworth)
return in1.nworth > in2.nworth;
else if (in1.age != in2.age)
return in1.age < in2.age;
else
return strcmp(in1.name, in2.name) < 0;
}
int main()
{
int N, K;
scanf("%d%d", &N, &K);
vector<Info> richests(N);
for (int i = 0; i < N; i++)
{
scanf("%s %d %d", richests[i].name, &(richests[i].age), &(richests[i].nworth));
}
sort(richests.begin(), richests.end(), cmp);
int validNum = 0;
int ageNum[201] = { 0 }; //某年龄的人数
vector<Info> valid;
for (int i = 0; i < N; i++)
{
if (ageNum[richests[i].age] < 100)
{
ageNum[richests[i].age]++;
valid.push_back(richests[i]);
}
}
for (int i = 0; i < K; i++)
{
int m;
int amin, amax;
scanf("%d%d%d", &m, &amin, &amax);
printf("Case #%d:\n", i+1);
int cnt = 0; // 已输出的人数
for (int j = 0; j < valid.size() && cnt < m; j++)
{
if (valid[j].age >= amin&&valid[j].age <= amax)
{
printf("%s %d %d\n", valid[j].name, valid[j].age, valid[j].nworth);
cnt++;
}
}
if (cnt == 0)
printf("None\n");
}
return 0;
}