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

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

解题思路:注意这里有一个坑,就是可能有空格作为当前的名字比如说:  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;
}
				
时间: 2024-09-19 08:19:26

hdu 5427 A problem of sorting的相关文章

算法题:HDU 1022 Train Problem I 栈

As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to school by train(because the trains in the Ignatius Train Station is the fastest all over the world ^v^). But here comes a problem, there is

hdu 3374 String Problem

点击打开链接hdu 3374 思路:求最小/最大表示+kmp匹配 分析: 1 题目要求给定一个字符串求出最小和最大表示的rank和出现的times. 2 如果直接暴力枚举n 最大10^6肯定TLE,所以这了应该要用到的是求解一个字符串的最小和最大表示,然后利用kmp去匹配查找出现的次数 3 在利用kmp匹配的时候应该要注意不能多算,比如有abcder,那么用abcder去匹配abcderabcder的时候就有两次的匹配结果,但实际上这里只有一个,所以这个地方要注意. 代码: #include<i

HDOJ/HDU 1022 Train Problem I(模拟栈)

Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to school by train(because the trains in the Ignatius Train Station is the fastest all over the world ^v^). But here comes

hdu 1568 Fibonacci

点击此处即可传送hdu 1568 **Fibonacci** Problem Description 2007年到来了.经过2006年一年的修炼,数学神童zouyu终于把0到100000000的Fibonacci数列 (f[0]=0,f[1]=1;f[i] = f[i-1]+f[i-2](i>=2))的值全部给背了下来. 接下来,CodeStar决定要考考他,于是每问他一个数字,他就要把答案说出来,不过有的数字太长了.所以规定超过4位的只要说出前4位就可以了,可是CodeStar自己又记不住.于

Google China New Grad Test 2014 Round A Problem C

Problem C. Sorting Problem Alex and Bob are brothers and they both enjoy reading very much. They have widely different tastes on books so they keep their own books separately. However, their father thinks it is good to promote exchanges if they can p

KMP专题【完结】

第一题 hdu 1711 Number Sequence 点击打开hdu 1711 思路: 1 kmp是用来匹配字符串,只能够匹配单一的字符串 2 kmp的算法的过程:   1:假设文本串的长度为n,模式串的长度为m:   2:先例用O(m)的时间去预处理next数组,next数组的意思指的是当前的字符串匹配失败后要转到的下一个状态:   3:利用o(n)的时间去完成匹配: 3 时间复杂度为o(n+m)即o(n): 点击查看代码 第二题 hdu 1686 oulipo 点击打开hdu 1686

UVa 331 Mapping the Swaps (DFS)

331 - Mapping the Swaps Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=108&page=show_problem&problem=267 Sorting an array can be done by swapping certain pairs of adjacent entries in

寻找最小的k个数

题目描述 输入n个整数,输出其中最小的k个. 分析与解法 解法一 要求一个序列中最小的k个数,按照惯有的思维方式,则是先对这个序列从小到大排序,然后输出前面的最小的k个数. 至于选取什么的排序方法,我想你可能会第一时间想到快速排序(我们知道,快速排序平均所费时间为  n*logn  ),然后再遍历序列中前k个元素输出即可.因此,总的时间复杂度:  O(n * log n)+O(k)=O(n * log n)  . 解法二 咱们再进一步想想,题目没有要求最小的k个数有序,也没要求最后n-k个数有序

hdu 5349 MZL&amp;#39;s simple problem

hdu 5349 的传送门 Problem Description A simple problem Problem Description You have a multiple set,and now there are three kinds of operations: 1 x : add number x to set 2 : delete the minimum number (if the set is empty now,then ignore it) 3 : query the