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 100T≤100 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(1≤n≤100) 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 水的更多相关文章

  1. Codeforces Beta Round #54 (Div. 2)

    Codeforces Beta Round #54 (Div. 2) http://codeforces.com/contest/58 A 找子序列 #include<bits/stdc++.h ...

  2. Codeforces Round #365 (Div. 2) A 水

    A. Mishka and Game time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  3. Codeforces Round #303 (Div. 2) B 水 贪心

    B. Equidistant String time limit per test 1 second memory limit per test 256 megabytes input standar ...

  4. Codeforces Round #303 (Div. 2) A 水

    A. Toy Cars time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  5. Codeforces Round #394 (Div. 2)A水 B暴力 C暴力 D二分 E dfs

    A. Dasha and Stairs time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  6. Codeforces Round #169 (Div. 2) A水 B C区间更新 D 思路

    A. Lunch Rush time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  7. Codeforces Round #337 (Div. 2) A水

    A. Pasha and Stick time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  8. Codeforces Round #364 (Div. 2) A 水

    A. Cards time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

  9. Codeforces Round #316 (Div. 2) A 水

    A. Elections time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

随机推荐

  1. Lua学习笔记(1): HelloWorld和数据类型

    Lua是一个轻量级的脚本语言,由c语言编写,容易嵌入到应用中,深受游戏开发者的青睐 环境安装 选用SciTE作为lua的IDE 可以在github找到这个开源的软件 SciTE下载链接 安装好之后打开 ...

  2. 周期串 (Periodic Strings,UVa455)

    #include<stdio.h> #include<string.h> int main(void) { int n,stlen,i,j; ]; while(scanf(&q ...

  3. Bootstrap框架(组件)

    按钮组 通过按钮组容器把一组按钮放在同一行里.通过与按钮插件联合使用,可以设置为单选框或多选框的样式和行为. 按钮组中的工具提示和弹出框需要特别的设置 当为 .btn-group 中的元素应用工具提示 ...

  4. Docker容器的搭建

    Docker容器的搭建 一.先从Docker Hub上面拉取一个基础镜像 命令:docker pull ubuntu 命令说明:pull:拉取镜像的命令,ubuntu:拉取镜像的名称 扩展命令: 命令 ...

  5. sqlserver 2008 merger语句

    Merge关键字是一个神奇的DML关键字.它在SQL Server 2008被引入,它能将Insert,Update,Delete简单的并为一句.MSDN对于Merge的解释非常的短小精悍:”根据与源 ...

  6. 并查集(Union/Find)模板及详解

    概念: 并查集是一种非常精巧而实用的数据结构,它主要用于处理一些不相交集合的合并问题.一些常见的用途有求连通子图.求最小生成树的Kruskal 算法和求最近公共祖先等. 操作: 并查集的基本操作有两个 ...

  7. 让我们一起来做最漂亮的Android界面吧!

    让我们一起来做最漂亮的Android界面吧! AndroidiOS产品设计 摘要:如何为Android设备量身定制以打造出最为完美的应用?这是让诸多开发者很是头疼的问题.不同于iOS,Android设 ...

  8. 如果jsp表单元素的值为空,如何避免null出现在页面上?

    可以写一个简单的函数对空值进行处理,判断值是否为空,如果是空就返回空字符串.实例代码如下: <%! String blanknull(String s) { return (s == null) ...

  9. UVA725 Division (暴力求解法入门)

    uva 725 Division Write a program that finds and displays all pairs of 5-digit numbers that between t ...

  10. HttpServletRequest和HttpServletResponse实例

    先看一下web.xml文件配置: <?xml version="1.0" encoding="UTF-8"?> <web-app versio ...