A problem of sorting
2015-09-05 20:55
363 查看
Problem Description
There are many people's name and birth in a list.Your task is to print the name from young to old.(There is no pair of two has the same age.)
Input
First line contains a single integer T \leq 100T≤100 which denotes the number of test cases.
For each test case, there is an positive integer n (1 \leq n \leq 100)n(1≤n≤100) which denotes the number of people,and next nn lines,each line has a name and a birth's year(1900-2015) separated by one space.
The length of name is positive and not larger than 100100.Notice name only contain letter(s),digit(s) and space(s).
Output
For each case, output nn lines.
Sample Input
Sample Output
There are many people's name and birth in a list.Your task is to print the name from young to old.(There is no pair of two has the same age.)
Input
First line contains a single integer T \leq 100T≤100 which denotes the number of test cases.
For each test case, there is an positive integer n (1 \leq n \leq 100)n(1≤n≤100) which denotes the number of people,and next nn lines,each line has a name and a birth's year(1900-2015) separated by one space.
The length of name is positive and not larger than 100100.Notice name only contain letter(s),digit(s) and space(s).
Output
For each case, output nn lines.
Sample Input
2 1 FancyCoder 1996 2 FancyCoder 1996 xyz111 1997
Sample Output
FancyCoder xyz111 FancyCoder
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; struct p { int eag; char name[105]; };p s[105]; bool com(p A,p B) { return A.eag>B.eag; } int pow(int x,int y) { int n=1,i; for (i=0;i<y;i++) n*=x; return n; } int main() { int t,n,n2,i,l,j,k; char ss[205]; scanf("%d",&t); while (t--) { k=0; scanf("%d",&n); n2=n; getchar(); while (n--) { j=0; s[k].eag=0; gets(ss); l=strlen(ss); for (i=l-1;i>=0;i--) { if (ss[i]==' ') break; s[k].eag+=(ss[i]-'0')*pow(10,j); j++; } // printf("%d\n",s[k].eag); for (j=0;j<i;j++) s[k].name[j]=ss[j]; s[k].name[j]='\0'; k++; } sort(s,s+n2,com); for (i=0;i<n2;i++) printf("%s\n",s[i].name); } }
相关文章推荐
- JavaScript学习笔记(一)
- 分而治之
- centos 安装jdk
- 1007. 素数对猜想 (20)
- Android用户界面设计:框架布局(转)
- 仿微信主页的切换
- 自我评价
- bc #54 A problem of sorting
- Linux命令学习(二)_centos7不使用inittab
- jieba中文分词源码分析(二)
- 二叉树三种遍历六种实现
- Uva-11526 H(n)
- OC---面向对象编程思想
- Android与服务器端数据交互(转)
- (转) 安卓实现parcelable接口作用
- c语言学习之顺序结构
- 集合
- 江雪
- SpringMVC上传文件实例
- 用android LinearLayout和RelativeLayout实现精确布局(转)