A problem of sorting
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1215 Accepted Submission(s): 485
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≤100
which denotes the number of test cases.
For each test case, there is an positive integer n(1≤n≤100) which denotes the number of people,and next n 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 100.Notice name only contain letter(s),digit(s) and space(s).
For each test case, there is an positive integer n(1≤n≤100) which denotes the number of people,and next n 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 100.Notice name only contain letter(s),digit(s) and space(s).
Output
For each case, output n
lines.
Sample Input
2 1 FancyCoder 1996 2 FancyCoder 1996 xyz111 1997
Sample Output
FancyCoder xyz111 FancyCoder 题意:给出一张许多人的年龄和生日表。你需要从年轻到年老输出人们的名字。(没有人年龄相同) 注意:姓名可以含有空格 ac代码:#include<stdio.h> #include<math.h> #include<string.h> #include<stack> #include<queue> #include<iostream> #include<algorithm> #define MAXN 10001 #define LL long long #define INF 0x7fffffff #define mem(x) memset(x,0,sizeof(x)) using namespace std; struct s { char name[110]; int num; }a[110]; bool cmp(s a,s b) { return a.num>b.num; } int main() { int t,i,j; int n; char ss[1010]; char str[1010]; scanf("%d",&t); while(t--) { scanf("%d",&n); getchar(); for(i=0;i<n;i++) { gets(ss); //printf("yes\n"); int len=strlen(ss); int q=0; int k=1; int w=0; int bz=0; for(j=len-1;j>=0;j--) { if(ss[j]==' '&&bz==0) { bz=1; continue; } if(bz) { str[w++]=ss[j]; } else { q=q+(ss[j]-'0')*k; k*=10; } } a[i].num=q; k=0; for(j=w-1;j>=0;j--) a[i].name[k++]=str[j]; a[i].name[k]='\0'; //getchar(); } sort(a,a+n,cmp); for(i=0;i<n;i++) printf("%s\n",a[i].name); } return 0; }