1055. The World's Richest (25)

 1 #include <stdio.h>
 2 #include <vector>
 3 #include<string.h>
 4 #include<algorithm>
 5 using namespace std;
 6
 7 struct MyStruct
 8 {
 9     char name[9];
10     int age,worth;
11 };
12
13 int cmp(MyStruct a,MyStruct b)
14 {
15     if(a.worth!=b.worth) return a.worth>b.worth;
16     else
17     {
18         if(a.age!=b.age) return a.age<b.age;
19         else
20         {
21             return (strcmp(a.name,b.name)<0);
22         }
23     }
24 }
25
26 int main()
27 {
28     int n,k,i,j,Max,low,high;
29     while(scanf("%d %d",&n,&k)!=EOF)
30     {
31         vector<MyStruct> vv;
32         for(i=0;i<n;i++)
33         {
34             getchar();
35             MyStruct tem;
36             scanf("%s %d %d",tem.name,&tem.age,&tem.worth);
37             vv.push_back(tem);
38         }
39
40         sort(vv.begin(),vv.end(),cmp);
41
42         vector<MyStruct> VV2;
43         int Age[201];
44         for(i=1;i<=200;i++)
45             Age[i]=0;
46
47         for(i=0;i<n;i++)
48             if(Age[vv[i].age]<100)
49             {
50                 ++Age[vv[i].age];
51                 VV2.push_back(vv[i]);
52             }
53
54         for(i=0;i<k;i++)
55         {
56             getchar();
57             scanf("%d %d %d",&Max,&low,&high);
58             printf("Case #%d:\n",i+1);
59
60             int printNum = 0;
61
62             for(j=0;j<VV2.size() && printNum < Max ;j++)
63             {
64                 if( VV2[j].age >= low && VV2[j].age <= high )
65                 {
66                     printf("%s %d %d\n",VV2[j].name,VV2[j].age,VV2[j].worth);
67                     ++printNum;
68                 }
69             }
70
71             if(printNum==0) printf("None\n");
72
73         }
74     }
75    return 0;
76 }

1055. The World's Richest (25)

时间: 2024-07-28 22:14:16

1055. The World's Richest (25)的相关文章

PAT:1055. The World&#39;s Richest (25) AC

#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; struct Person { char name[10]; int age,money; }P[100010]; bool cmp(Person a,Person b) { if(a.money!=b.money) return a.money>b.money; else if(a.age!=b.age) r

PAT (Advanced Level) 1055. The World&#39;s Richest (25)

排序.随便加点优化就能过. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<map> #include<queue> #include<string> #include<stack> #include<vector> using names

1055 The World&#39;s Richest (25 分)

1055 The World's Richest (25 分) Forbes magazine publishes every year its list of billionaires based on the annual ranking of the world's wealthiest people. Now you are supposed to simulate this job, but concentrate only on the people in a certain ran

PAT Advanced 1055 The World&#39;s Richest (25分)

Forbes magazine publishes every year its list of billionaires based on the annual ranking of the world's wealthiest people. Now you are supposed to simulate this job, but concentrate only on the people in a certain range of ages. That is, given the n

1055 The World&#39;s Richest (25分)

1. 题目 2. 思路 常规题 3. 注意点 注意超时 4. tip 善于使用题目的条件来减少数据量 fill(begin, end, value)注意[begin, end) 2. 代码 #include<cstdio> #include<algorithm> #include<string> #include<vector> #include<iostream> // 14:57 - using namespace std; struct p

pat1055. The World&#39;s Richest (25)

1055. The World's Richest (25) 时间限制 400 ms 内存限制 128000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Forbes magazine publishes every year its list of billionaires based on the annual ranking of the world's wealthiest people. Now you are supposed to si

PAT-1055. The World&#39;s Richest (25)

这道题目就是一个排序题目,但是如果简单的排序会超时,需要剪掉一部分数据. 最多输出100名数据,排序后,那么相同年龄的后面的数据就不会输出了,所以也不需记录在查找序列里面.因此这部分数据可以忽略掉. bool cmp  return true means right position. make_heap(iterato_begin,iterator_end); heap_sort(iterator_begin,iterator_end); 堆排序. // 1055.cpp : 定义控制台应用程

PAT 1055 The World&#39;s Richest

#include <cstdio> #include <cstdlib> #include <cstring> #include <vector> #include <queue> #include <algorithm> using namespace std; #define AGE_MAX 200 class People { public: char name[9]; int worth; int age; int idx;

1055. The World&#39;s Richest

Forbes magazine publishes every year its list of billionaires based on the annual ranking of the world's wealthiest people. Now you are supposed to simulate this job, but concentrate only on the people in a certain range of ages. That is, given the n