zoukankan      html  css  js  c++  java
  • bc #54 A problem of sorting

    A problem of sorting

     
     Accepts: 445
     
     Submissions: 1706
     Time Limit: 2000/1000 MS (Java/Others)
     
     Memory Limit: 65536/65536 K (Java/Others)
    问题描述
    给出一张许多人的年龄和生日表。你需要从年轻到年老输出人们的名字。(没有人年龄相同)
    
    输入描述
    第一行包含一个正整数T(T leq 5)T(T5),表示数据组数。
    对于每组数据,第一行包含一个正整数n(1 leq n leq 100)n(1n100),表示人数,接下来n行,每行包含一个姓名和生日年份(1900-2015),用一个空格隔开。姓名长度大于0且不大于100。注意姓名中只包含字母,数字和空格。
    
    输出描述
    对于每组数据,输出nn行姓名。
    
    输入样例
    2
    1
    FancyCoder 1996
    2
    FancyCoder 1996
    xyz111 1997
    
    输出样例
    FancyCoder
    xyz111
    FancyCoder


    字符串处理...
    因为名字中可能有空格
    所以我们只能整体读入,再分析.
    用getline(cin,st);
    用一个结构体排序..
    用到了string 类字符串转整型函数

    sigh,字符串那些函数看来还是不够熟悉.
     1 /*************************************************************************
     2     > File Name: code/bc/#54/A.cpp
     3     > Author: 111qqz
     4     > Email: rkz2013@126.com 
     5     > Created Time: 2015年09月05日 星期六 18时56分22秒
     6  ************************************************************************/
     7 
     8 #include<iostream>
     9 #include<iomanip>
    10 #include<cstdio>
    11 #include<algorithm>
    12 #include<cmath>
    13 #include<cstring>
    14 #include<string>
    15 #include<map>
    16 #include<set>
    17 #include<queue>
    18 #include<vector>
    19 #include<stack>
    20 #include<cctype>
    21 #include <cstdlib>
    22 #include <sstream>
    23 #define y1 hust111qqz
    24 #define yn hez111qqz
    25 #define j1 cute111qqz
    26 #define ms(a,x) memset(a,x,sizeof(a))
    27 #define lr dying111qqz
    28 using namespace std;
    29 #define For(i, n) for (int i=0;i<int(n);++i)  
    30 typedef long long LL;
    31 typedef double DB;
    32 const int inf = 0x3f3f3f3f;
    33 const int N=1E2+7;
    34 struct Q
    35 {
    36     string nam;
    37     int yea;
    38 }q[N];
    39 int n;
    40 int str2num(string s)
    41 {
    42     int num;
    43     stringstream ss(s);
    44     ss>>num;
    45     return num;
    46 }
    47 bool cmp(Q a,Q b)
    48 {
    49     if (a.yea>b.yea) return true;
    50     return false;
    51 }
    52 int main()
    53 {
    54   #ifndef  ONLINE_JUDGE 
    55     freopen("in.txt","r",stdin); 
    56   #endif
    57   int T;
    58   cin>>T;
    59   while (T--)
    60     {
    61     int p;
    62     scanf("%d",&n);
    63     getchar();
    64     for ( int i = 0 ; i < n ; i++){
    65         string tmp;
    66         int len = tmp.length();
    67         getline(cin,tmp);
    68         p = tmp.rfind(' ',len-1);
    69         q[i].nam=tmp.substr(0,p);
    70         string ye=tmp.substr(p+1);
    71         q[i].yea=str2num(ye);
    72     }
    73     sort(q,q+n,cmp);
    74     for ( int i = 0 ; i < n ; i++){
    75         cout<<q[i].nam<<endl;
    76     }
    77     }
    78  #ifndef ONLINE_JUDGE  
    79   fclose(stdin);
    80   #endif
    81     return 0;
    82 }
    View Code





  • 相关阅读:
    PHP线程安全
    Oracle中MD5+Base64加密实现
    1002. A+B for Polynomials (25)
    1001. A+B Format (20)
    Rails,uva 514
    Database,Uva1592
    Hello World for U
    D3.js 力导向图
    从零开始CSS(一 2016/9/21)
    从零开始HTML(三 2016/9/20)
  • 原文地址:https://www.cnblogs.com/111qqz/p/4783911.html
Copyright © 2011-2022 走看看