PAT:1055. The World'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)
    return a.age<b.age;
  else
    return strcmp(a.name,b.name)<0;
}
int main()
{
  int N,K;
  scanf("%d%d",&N,&K);
  for(int i=0 ; i<N ; ++i)
  {
    scanf("%s %d %d",&P[i].name, &P[i].age, &P[i].money);
  }
  sort(P,P+N,cmp);

  for(int t=1 ; t<=K ; ++t)      //查询K次
  {
    int cnt=0,Qpeople,Qyoung,Qold;  //输出记录cnt,输出查询最大人数,最低年龄,最高年龄
    scanf("%d%d%d",&Qpeople, &Qyoung, &Qold);
    printf("Case #%d:\n",t);
    for(int i=0 ; i<N ; ++i)
    {
      if(cnt==Qpeople){      //输出已足够
        break;
      }
      if(P[i].age>=Qyoung && P[i].age<=Qold)
      {
        printf("%s %d %d\n",P[i].name, P[i].age, P[i].money);
        ++cnt;
      }
    }
    if(0==cnt){
      printf("None\n");
    }
  }
  return 0;
}

PAT:1055. The World's Richest (25) AC

时间: 2024-08-05 11:17:54

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

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

PAT:1047. Student List for Course (25) AC

#include<stdio.h> #include<string.h> #include<vector> #include<algorithm> using namespace std; const int MAX=40010; int n,k; //n个人,k门课 char name[MAX][5]; //存n个人的名字 vector<int> course[MAX]; //记录每个课程选的学生 bool cmp(int a,int b) {

PAT:1005. 继续(3n+1)猜想 (25) AC

#include<stdio.h> #include<algorithm> using namespace std; bool HARSH[10066]; //实际上申请来之后初试都是false bool cmp(int a,int b) { return a>b; } int main() { fill(HARSH,HARSH+1066,false); int n; scanf("%d",&n); int arr[1006],cnt=0; for

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

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

1055. The World&#39;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.w

PAT:1010一元多项式求导 (25 )

PAT乙级的题目相对于甲级的题目较为简单,但是有时候也会有一两道题很奇怪,具有一定的逻辑难度,这道题就是一个例子. 先看一下题目: 010 一元多项式求导 (25 分)设计函数求一元多项式的导数.(注:x?n??(n为整数)的一阶导数为nx?n?1??.)输入格式:以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过 1000 的整数).数字间以空格分隔.输出格式:以与输入相同的格式输出导数多项式非零项的系数和指数.数字间以空格分隔,但结尾不能有多余空格.注意"零多项式"的指数和

PAT:1002. A+B for Polynomials (25) 部分错误

#include<stdio.h> #include<stdlib.h> #include<string.h> //[warning]double 输入%lf,输出%f struct arr { int tag; double data; }arr[1005]; int main() { memset(arr,0,sizeof(arr)); int t1,t2,tmp,maxI=0; //maxI记录最多多少项 double tdata; for(int I=0 ; I