您的位置:首页 > 其它

HDU 5427 A problem of sorting(字符串处理+排序)——BestCoder Round #54(div.2)

2015-09-05 21:57 525 查看


A problem of sorting

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

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).

 

Output

For each case, output n lines.

 

Sample Input

2
1
FancyCoder 1996
2
FancyCoder 1996
xyz111 1997
 

Sample Output

FancyCoder
xyz111
FancyCoder
 

Source

BestCoder Round #54 (div.2)

 

/************************************************************************/

附上该题对应的中文题


A problem of sorting

 
 

 Time Limit: 2000/1000 MS (Java/Others)
 
 Memory Limit: 65536/65536 K (Java/Others)

问题描述
给出一张许多人的年龄和生日表。你需要从年轻到年老输出人们的名字。(没有人年龄相同)


输入描述
第一行包含一个正整数T(T \leq 5)T(T≤5),表示数据组数。
对于每组数据,第一行包含一个正整数n(1 \leq n \leq 100)n(1≤n≤100),表示人数,接下来n行,每行包含一个姓名和生日年份(1900-2015),用一个空格隔开。姓名长度大于0且不大于100。注意姓名中只包含字母,数字和空格。


输出描述
对于每组数据,输出nn行姓名。


输入样例
2
1
FancyCoder 1996
2
FancyCoder 1996
xyz111 1997


输出样例
FancyCoder
xyz111
FancyCoder

/****************************************************/

出题人的解题思路:


A problem of sorting

选择任意喜欢的排序方法即可。注意名字中可能有空格。
说实话,这题还是比较简单的,初看,只要按年份从大到小排序就可以了

但题目中提到,“注意姓名中只包含字母,数字和空格”,“空格”,好吧,不能直接%s了,再看,年份的范围是1900-2015,一定是4位的,那我只需用gets读入之后,特殊处理字符串的后4个字符就可以搞定了
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<stdlib.h>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#define exp 1e-10
using namespace std;
const int N = 120;
const int inf = 2147483647;
const int mod = 2009;
struct person
{
char name
;
int year;
}s
;
bool cmp(person x,person y)
{
return x.year>y.year;
}
int main()
{
int t,n,i,j,l;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
getchar();
for(i=0;i<n;i++)
{
s[i].year=0;
gets(s[i].name);
l=strlen(s[i].name);
for(j=l-4;j<l;j++)
s[i].year=s[i].year*10+s[i].name[j]-'0';
s[i].name[l-5]='\0';
}
sort(s,s+n,cmp);
for(i=0;i<n;i++)
printf("%s\n",s[i].name);
}
return 0;
}菜鸟成长记
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: