A problem of sorting----(BestCoder Round #54 (div.2))
来源:互联网 发布:迅雷看看优化版 编辑:程序博客网 时间:2024/06/06 09:53
A problem of sorting
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
问题描述
给出一张许多人的年龄和生日表。你需要从年轻到年老输出人们的名字。(没有人年龄相同)
输入描述
第一行包含一个正整数T(T≤5),表示数据组数。对于每组数据,第一行包含一个正整数n(1≤n≤100),表示人数,接下来n行,每行包含一个姓名和生日年份(1900-2015),用一个空格隔开。姓名长度大于0且不大于100。注意姓名中只包含字母,数字和空格。
输出描述
对于每组数据,输出n行姓名。
输入样例
21FancyCoder 19962FancyCoder 1996xyz111 1997
输出样例
FancyCoderxyz111FancyCoder
分析:题意很简单,第一次提交wa了,然后仔细重读一遍题目,注意到最后一句话:
注意姓名中只包含字母,数字和空格。
思路:用gets或getline读取整个句子,名字为去掉最后5个字符,年份为最后4个字符。
CODE:
#include <iostream>#include <algorithm>#include <cmath>#include <string.h>#include <cstdio>using namespace std;struct node{ char s[105]; int y;}p[1005];int cmp(node a,node b){ return a.y>b.y;}int main(){ int t; cin>>t; while(t--){ int n; cin>>n; getchar(); for(int i=0;i<n;i++){ gets(p[i].s); int len=strlen(p[i].s); p[i].y=p[i].s[len-4]*1000+p[i].s[len-3]*100+p[i].s[len-2]*10+p[i].s[len-1]; } sort(p,p+n,cmp); for(int i=0;i<n;i++){ int len=strlen(p[i].s); for(int j=0;j<len-5;j++) printf("%c",p[i].s[j]); printf("\n"); } } return 0;}
0 0
- A problem of sorting----(BestCoder Round #54 (div.2))
- BestCoder Round #54 (div.2) HDU5427 A problem of sorting
- HDU 5427 A problem of sorting(字符串处理+排序)——BestCoder Round #54(div.2)
- BestCoder Round #54 (div.2) HDOJ 5427 A problem of sorting(模拟)
- BestCoder Round #54 (div.2) HDU 5427 A problem of sorting(1001)
- Bestcoder#54 A problem of sorting
- BestCoder Round #54 (div.2)
- A problem of sorting
- BestCoder Round #51 (div.2) A
- BestCoder Round #59 (div.2)A.SDOI
- BestCoder Round #77 (div.2)(A)
- BestCoder Round #76 (div.2)A
- BestCoder Round #78 (div.2) A B
- BestCoder Round #81 (div.2)A
- BestCoder Round #82 (div.2) A B
- BestCoder Round #11 (Div. 2)--Bob and math problem
- BestCoder Round #56 (div.2)(Clarke and problem)
- hdu 5464 Clarke and problem (BestCoder Round #56 (div.2))
- Caused by: java.lang.IllegalArgumentException: addChild: Child name 'localhost' is not unique
- easy ui jquery 添加时样式出现问题
- jquery+ajax简单例子及jquery事件
- 数据结构——有序线性表的的插入与删除
- iOS sqlite 数据库加密
- A problem of sorting----(BestCoder Round #54 (div.2))
- react-native试玩(33)-状态栏API
- CSS 最核心的几个概念
- Liner(分段线性插值)
- Java 利用 HttpURLConnection 读取页面 返回字节流(生成静态页面)
- android开发记录
- BeanFactory接口包含基本方法
- 枚举类型(C#)
- python:open/文件操作