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
| #include <iostream> #include <algorithm> #include <vector> #include <string> #include <unordered_map> using namespace std;
struct person { string name; int age; int worth; person(const string &name, const int &age, const int &worth) : name(name), age(age), worth(worth) { } };
int main() { vector<person> P; int n, k; cin >> n >> k;
for (int i = 0; i < n; i++) { string name; int age; int worth; cin >> name >> age >> worth; P.emplace_back(name, age, worth); }
sort(P.begin(), P.end(), [](const person &p1, const person &p2) { return (p1.worth != p2.worth ? p1.worth > p2.worth : (p1.age != p2.age ? p1.age < p2.age : p1.name < p2.name)); });
vector<person> P1; unordered_map<int, int> AgeCount; for (int i = 0; i < n; i++) { if (AgeCount[P[i].age] <= 100) { AgeCount[P[i].age]++; P1.emplace_back(P[i]); } }
for (int i = 0; i < k; i++) { int m, amin, amax, count = 0; cin >> m >> amin >> amax; cout << "Case #" << i + 1 << ":" << endl; for (auto &&p : P1) { if (p.age >= amin && p.age <= amax) { cout << p.name << " " << p.age << " " << p.worth << endl; count++; if (count >= m) break; } } if (count == 0) { cout << "None" << endl; } }
return 0; }
|