zoukankan      html  css  js  c++  java
  • hdu 5427 A problem of sorting 水题

    A problem of sorting

    Time Limit: 1 Sec  

    Memory Limit: 256 MB

    题目连接

    http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=627&pid=1001

    Description

    给出一张许多人的年龄和生日表。你需要从年轻到年老输出人们的名字。(没有人年龄相同)

    Input

    第一行包含一个正整数T(T leq 5)T(T5),表示数据组数。
    对于每组数据,第一行包含一个正整数n(1 leq n leq 100)n(1n100),表示人数,接下来n行,每行包含一个姓名和生日年份(1900-2015),用一个空格隔开。姓名长度大于0且不大于100。注意姓名中只包含字母,数字和空格。

    Output

    对于每组数据,输出nn行姓名。

    Sample Input

    FancyCoder
    xyz111
    FancyCoder

    Sample Output

     

    HINT

     

    题意

    排序,然后输出名字

    从年轻到年老,名字中可能有空格

    题解:

    数字永远都是最后四个,所以处理一下就好了

    代码:

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <bitset>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 1000
    #define mod 10007
    #define eps 1e-9
    int Num;
    //const int inf=0x7fffffff;   //§ß§é§à§é¨f§3
    const int inf=0x3f3f3f3f;
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    //**************************************************************************************
    
    struct node
    {
        char s[1000];
        int age;
    }a[maxn];
    int n;
    int kiss[maxn];
    bool cmp(int aa,int bb)
    {
        return a[aa].age>a[bb].age;
    }
    int main()
    {
        int t=read();
        while(t--)
        {
            int n=read();
            memset(kiss,0,sizeof(kiss));
            memset(a,0,sizeof(a));
            for(int i=0;i<n;i++)
            {
                int len = 0;
                a[i].age=0;
                cin.getline(a[i].s,1000);
                len = strlen(a[i].s);
                 for(int j=1;j<=4;j++)
                     a[i].age=a[i].age*10+a[i].s[len-5+j]-'0';
                a[i].s[len-5]='';
                kiss[i]=i;
            }
            sort(kiss,kiss+n,cmp);
            for(int i=0;i<n;i++)
                printf("%s
    ",a[kiss[i]].s);
        }
    }
  • 相关阅读:
    YGC问题排查,又让我涨姿势了!
    AI时代,还不了解大数据?
    实战篇:一个核心系统 3 万行代码的重构之旅
    监控系统选型,这篇不可不读!
    实时离线一体大数据在资产租赁saas服务中使用
    基于监控服务打造微服务治理生态体系
    CDH6.3.2升级Hive到4.0.0
    强化学习 9 —— DQN 改进算法DDQN、Dueling DQN tensorflow 2.0 实现
    强化学习 8 —— DQN 算法 Tensorflow 2.0 实现
    强化学习 7——Deep Q-Learning(DQN)公式推导
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4784063.html
Copyright © 2011-2022 走看看