Sample Input
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
Sample Output
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
思路:
注意审题,None写错了第一个点就会错,第三个点评测姬不是很稳,可能超时,改的我自闭。
代码
#include <bits/stdc++.h>
using namespace std;
struct node {
string name;
int age;
int score;
}p[100005];
bool cmp(node a, node b)
{
if (a.score != b.score)
return a.score > b.score;
if (a.age != b.age)
return a.age < b.age;
return a.name < b.name;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, k;
cin >> n >> k;
for (int i = 0; i < n; ++i)
{
cin >> p[i].name >> p[i].age >> p[i].score;
}
sort(p, p + n, cmp);
for (int i = 0; i < k; ++i)
{
int m, amin, amax;
cin >> m >> amin >> amax;
cout << "Case #" << i + 1 << ":" << endl;
int num = 0;
for (int j = 0; j < n; ++j)
{
if (p[j].age >= amin && p[j].age <= amax)
{
cout << p[j].name << " " << p[j].age << " " << p[j].score << endl;
num++;
// v.push_back(p[j]);
}
if (num == m) break;
}
if (num == 0)
cout << "None" << endl;
}
return 0;
}