HDU5427

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cstring>
 4 #include<algorithm>
 5 using namespace std;
 6 const int maxn = 120;
 7 char str[maxn];
 8 
 9 struct node{
10     char s[120];
11     int year;
12 }p[maxn];
13 
14 int cmp(node A, node B)
15 {
16     return A.year > B.year;  //不要忽略这个细节,可能你会习惯性的用小于号。
17 }
18 
19 int main()
20 {
21     int t, n;
22     scanf("%d", &t);
23     while(t --)
24     {
25         scanf("%d", &n);
26         getchar(); //吃掉回车
27         for(int i = 0; i < n; i++)
28         {
29             gets(str); //明显用gets(),scanf()连空格都不吃
30             int len = strlen(str);
31             p[i].year = 0;
32             for(int j = len - 4; j <= len - 1; j++) p[i].year = 10 * p[i].year + str[j] - '0';
33             for(int j = 0; j < len - 5; j++) p[i].s[j] = str[j];
34             p[i].s[len-5] = '\0';  //极为关键的一步,必须标记字符串结束标志,不然会多输出一些字符。
35         }
36         sort(p, p + n, cmp);
37         for(int i = 0; i < n; i++) printf("%s\n", p[i].s);
38     }
39     return 0;
40 }

 

转载于:https://www.cnblogs.com/loveprincess/p/4784818.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值