hdu 5427 A problem of sorting

简介:

点击打开链接

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 100T100 which denotes the number of test cases.

For each test case, there is an positive integer n (1 \leq n \leq 100)n(1n100) 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

题目大意:就是让你排序,按照从大到小排序,然后输出姓名就行了

解题思路:注意这里有一个坑,就是可能有空格作为当前的名字比如说:  ITAK,输出的时候也需要输出空格,这就需要用到cin.getline了,这个就是能读单字符的。。。

读入啥,输出啥,可以手动实现一下:


上代码:

</pre><pre name="code" class="cpp"><pre name="code" class="cpp">/*
Date : 2015-09-05 晚上

Author : ITAKING

Motto :

今日的我要超越昨日的我,明日的我要胜过今日的我;
以创作出更好的代码为目标,不断地超越自己。
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
struct sa
{
    char name[105];
    int date;
} arr[105];
int cmp(sa a, sa b)
{
    return a.date > b.date;
}
char str[200];
int main()
{
    int t,m;
    scanf("%d",&t);
    while(t--)
    {
        cin>>m;
        getchar();
        for(int i=0; i<m; i++)
        {
            cin.getline(str,200);//能够正常读入单字符
            int len = strlen(str);
            arr[i].date = str[len-4]*1000+str[len-3]*100+str[len-2]*10+str[len-1];
            len -= 5;
            str[len] = '\0';
            strcpy(arr[i].name,str);
        }
        sort(arr, arr+m, cmp);
        for(int i=0; i<m; i++)
            cout<<arr[i].name<<endl;
    }
    return 0;
}


 


目录
相关文章
UVa1531 - Problem Bee
UVa1531 - Problem Bee
49 0
UVa11714 - Blind Sorting
UVa11714 - Blind Sorting
52 0
ZOJ - Summer 2018 - Contest 1 by SBconscious - Problems - 1001: Saber
ZOJ - Summer 2018 - Contest 1 by SBconscious - Problems - 1001: Saber
94 0
|
机器学习/深度学习 自然语言处理
|
人工智能 Java 安全
HDU 1039 Easier Done Than Said?
Easier Done Than Said? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 12751    Accepted Subm...
801 0
【HDU 5572 An Easy Physics Problem】计算几何基础
2015上海区域赛现场赛第5题。 题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5572 题意:在平面上,已知圆(O, R),点B、A(均在圆外),向量V。
1034 0