• best code #54 div 2 A 水


    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;
    }
    
  • 相关阅读:
    以AO方式给SceneControl控件设置BaseHeight
    TreeView只能选中一个节点
    Excel导出DataTable
    TOCControl右键菜单
    Arcgis Engine符号化相关
    shapefile文件锁定问题
    ArcGIS符号库serverstyle文件编辑注意事项
    CentOS运维常用命令
    常用shell
    javascript浮点数相减、相乘出现一长串小数
  • 原文地址:https://www.cnblogs.com/hsd-/p/4783895.html
Copyright © 2020-2023  润新知