1055. The World's Richest (25)
来源:互联网 发布:淘宝网中老年冬装 编辑:程序博客网 时间:2024/06/14 17:08
看到一些题解说这题不进行相同年龄的前一百名处理会超时,我这个没处理也过了,是测试点改了还是代码怎么了?知道的请留言。。
#include <cstdio>#include <algorithm>#include <cstring>using namespace std;struct Person { char name[10]; int age, worth;}p[100005];int M, Amin, Amax;bool cmp(Person a, Person 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, 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].worth); } sort(p, p + n, cmp); for (int i = 0; i < k; i++) { scanf("%d %d %d", &M, &Amin, &Amax); printf("Case #%d:\n", i + 1); int t = 0, count = 0; //t为扫描所有人看是否符合条件的指针,count为已找到符合条件的人数 while(t < n && count < M){ if (p[t].age >= Amin && p[t].age <= Amax) { printf("%s %d %d\n", p[t].name, p[t].age, p[t].worth); count++; } t++; } if (count == 0) printf("None"); } return 0;}
阅读全文
0 0
- 【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)
- 1055. The World's Richest (25)
- 1055. The World's Richest (25)
- 1055. The World's Richest (25)
- PAT: 1055. The World's Richest (25)
- 1055. The World's Richest (25)
- 1055. The World's Richest (25)
- 1055. The World's Richest (25)
- 1055. The World's Richest (25)
- 1055. The World's Richest (25)
- 1055. The World's Richest (25)
- 1055. The World's Richest (25)
- PAT 1055. The World's Richest (25)
- 1055. The World's Richest (25)
- 1055. The World's Richest (25)
- sin之舞
- openGL坐标系
- Hibernate中的悲观锁与乐观锁
- Android TelephonyManager 监听手机来电
- [BZOJ3390]荒岛野人
- 1055. The World's Richest (25)
- UVA 272 TEX Quotes
- mysql grant
- Mybatis-Generator自动生成代码——Mybatis 深入浅出(二)
- 深度理解链式前向星(转载于ACdreamer大神)
- MJPG-streamer源码分析-主函数部分
- 【Linux基础系列之】pinctrl系统
- sentencePiece 分词原理学习
- struts2--struts2国际化