码迷,mamicode.com
首页 > 其他好文 > 详细

best code #54 div 2 A 水

时间:2015-09-05 21:59:54      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:

A problem of sorting

Accepts: 443
Submissions: 1696
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≤100T \leq 100T100 which denotes the number of test cases.

For each test case, there is an positive integer n(1≤n≤100)n (1 \leq n \leq 100)n(1n100) which denotes the number of people,and next nnn 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 100100100.Notice name only contain letter(s),digit(s) and space(s).

Output

For each case, output nnn lines.

Sample Input
2
1
FancyCoder 1996
2
FancyCoder 1996
xyz111 1997
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<map>
#include<queue>
using namespace std;
struct node
{
    char  name[105];
    int birthday;
    friend bool operator <(node a,node b)
    {
        return a.birthday<b.birthday;
    }
};
node q1,q2;
priority_queue<node>q;
int main()
{
    int t,n;
    while(scanf("%d",&t)!=EOF)
    {
        for(int i=1; i<=t; i++)
        {
            scanf("%d",&n);
            getchar();
            for(int j=1; j<=n; j++)
            {
                char str[105],strr[105];
                int birth;
                memset(strr,0,sizeof(strr));
                memset(str,0,sizeof(str));
                cin.getline(str,105);
                int len=strlen(str);
                birth=str[len-1]-‘0‘+(str[len-2]-‘0‘)*10+(str[len-3]-‘0‘)*100+(str[len-4]-‘0‘)*1000;
                for(int k=0; k<=len-1-5; k++)
                {
                    strr[k]=str[k];

                }
                strcpy(q1.name,strr);
                q1.birthday=birth;
                q.push(q1);
            }
            while(!q.empty())
            {
                q2=q.top();
                q.pop();
                cout<<q2.name<<endl;
            }
        }
    }
    return 0;
}

 

 

 

best code #54 div 2 A 水

标签:

原文地址:http://www.cnblogs.com/hsd-/p/4783895.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!