zoukankan      html  css  js  c++  java
  • 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 100T100 which denotes the number of test cases.

    For each test case, there is an positive integer n (1 leq n leq 100)n(1n100) 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
    
    Sample Output
    FancyCoder
    xyz111
    FancyCoder

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 using namespace std;
     5 struct p
     6 {
     7     int eag;
     8     char name[105];
     9 };p s[105];
    10 bool com(p A,p B)
    11 {
    12     return A.eag>B.eag;
    13 }
    14 int pow(int x,int y)
    15 {
    16     int n=1,i;
    17     for (i=0;i<y;i++) n*=x;
    18     return n;
    19 }
    20 int main()
    21 {
    22     int t,n,n2,i,l,j,k;
    23     char ss[205];
    24     scanf("%d",&t);
    25     while (t--)
    26     {
    27         k=0;
    28         scanf("%d",&n);
    29         n2=n;
    30         getchar();
    31         while (n--)
    32         {
    33             j=0;
    34             s[k].eag=0;
    35             gets(ss);
    36             l=strlen(ss);
    37             for (i=l-1;i>=0;i--)
    38             {
    39                 if (ss[i]==' ') break;
    40                 s[k].eag+=(ss[i]-'0')*pow(10,j);
    41                 j++;
    42             }
    43           //  printf("%d
    ",s[k].eag);
    44             for (j=0;j<i;j++) s[k].name[j]=ss[j];
    45             s[k].name[j]='';
    46             k++;
    47         }
    48         sort(s,s+n2,com);
    49         for (i=0;i<n2;i++) printf("%s
    ",s[i].name);
    50     }
    51 }
  • 相关阅读:
    Web前端之jQuery 的10大操作技巧
    Python开发者须知 —— Bottle框架常见的几个坑
    string、const char*、 char* 、char[]相互转换
    SLAM中的变换(旋转与位移)表示方法
    SLAM
    二叉搜索树(BST)
    Linux下OSG的编译和安装以及遇到的问题
    CMake--Set用法
    CMake--List用法
    php面向对象面试题
  • 原文地址:https://www.cnblogs.com/pblr/p/4783917.html
Copyright © 2011-2022 走看看