1055. The World's Richest (25)

#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>

using namespace std;

struct node
{
	char name[10];
	int age, worth;
};

int cmp(node n1, node n2)
{
	if(n1.worth != n2.worth)
	{
		return n1.worth > n2.worth;
	}

	if(n1.age != n2.age)
	{
		return n1.age < n2.age;
	}

	return strcmp(n1.name, n2.name) < 0;
}

int main()
{
	int n, k;
	scanf("%d%d", &n, &k);

	int i;
	vector<node> v;
	node nod;

	for(i = 1; i <= n; i++)
	{
		getchar();
		scanf("%s%d%d", nod.name, &nod.age, &nod.worth);

		v.push_back(nod);
	}

	sort(v.begin(), v.end(), cmp);

	int m, j, c, min, max;
	for(i = 1; i <= k; i++)
	{
		scanf("%d%d%d", &m, &min, &max);
		printf("Case #%d:\n", i);

		for(j = 0, c = 0; j < n && c < m; j++)
		{
			if(v[j].age >= min && v[j].age <= max)
			{
				c++;
				printf("%s %d %d\n", v[j].name, v[j].age, v[j].worth);
			}
		}

		if(c == 0)
		{
			printf("None\n");
		}
	}

	system("pause");
	return 0;
}

 

posted on 2025-11-23 17:09  王景迁  阅读(2)  评论(0)    收藏  举报

导航