题目链接: https://pintia.cn/problem-sets/994805342720868352/problems/994805421066272768
知识点:简单结构体
题型:简单排序
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + 10;
struct Node
{
int age, worth;
char name[10];
} node[maxn];
bool cmp(Node a, Node b)
{
if (a.worth != b.worth)
return a.worth > b.worth;
else if (a.age != b.age)
return a.age < b.age;
else
return strcmp(a.name, b.name) < 0;
}
int main()
{
int n, m, k, amin, amax;
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++)
{
scanf("%s %d %d", node[i].name, &node[i].age, &node[i].worth);
}
sort(node, node + n, cmp);
for (int i = 1; i <= k; i++)
{
scanf("%d%d%d", &m, &amin, &amax);
printf("Case #%d:\n", i);
int cnt = m;
for (int j = 0; j < n; j++)
{
if (node[j].age >= amin && node[j].age <= amax)
{
printf("%s %d %d\n", node[j].name, node[j].age, node[j].worth);
cnt--;
}
if (cnt == 0)
break;
}
if (cnt == m)
printf("None\n");
}
return 0;
}