1055. The World's Richest 解析
来源:互联网 发布:黑格尔的哲学思想知乎 编辑:程序博客网 时间:2024/06/07 20:19
按题目给出的年龄范围输出排序的问题。直接排好序,按要求输出就好。
#include <iostream>#include <algorithm>#include <cstring>#include <string>#include <vector>#include <map>#include <queue>#include <stack>#define MAX 100010using namespace std;int n,k;int m,mina,maxa;struct node{char name[9];int age;int worth;};node l[MAX];bool cmp(node n1,node n2){if(n1.worth != n2.worth)return n1.worth > n2.worth;else if(n1.age != n2.age)return n1.age < n2.age;elsereturn strcmp(n1.name,n2.name) < 0;}int main(){scanf("%d%d",&n,&k);for(int i = 0 ; i < n ;i++){scanf("%s%d%d",l[i].name,&l[i].age,&l[i].worth);}sort(&l[0],&l[0]+n,cmp);for(int i = 1 ;i <= k ;i ++){printf("Case #%d:\n",i);int size = 0;scanf("%d%d%d",&m,&mina,&maxa);int j = 0;while(j < n && size < m){if(l[j].age <= maxa && l[j].age >= mina){printf("%s %d %d\n",l[j].name,l[j].age,l[j].worth);size++;}j++;}if(size == 0)printf("None\n");}return 0;}
阅读全文
0 0
- 1055. The World's Richest 解析
- 1055. The World's Richest
- 1055.The World's Richest
- 1055. The World's Richest
- 1055. The World's Richest
- 1055. The World's Richest
- 【PAT】1055. The World's Richest (25)
- pat 1055. The World's Richest (25)
- pat 1055. The World's Richest (25)
- 1055. The World's Richest (25)
- <PAT>1055. The World's Richest
- 1055. The World's Richest (25)
- 1055. The World's Richest (25)
- PAT 1055. The World's Richest
- 【待修改】1055. The World's Richest
- 1055. The World's Richest (25)
- PAT: 1055. The World's Richest (25)
- 1055. The World's Richest (25)
- java并发编程实战-显式锁
- Retrofit源码解析(二)
- Qt for Android获取手机序列号/手机型号/手机制造商
- 函数返回局部变量
- nginx启动重启与升级以及检测配置文件
- 1055. The World's Richest 解析
- 基于bootstrap的web登陆实例
- 二分搜索
- caffe学习之二----mnist集合训练及其测试
- Flask学习笔记-- 4
- 百练OJ:2800:垂直直方图
- 将本地工程上传到github
- 命运(hdu2571)
- 有关JavaScript中浅拷贝、深拷贝的简单研究