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 }

 

posted on 2015-09-06 10:49  改写历史,倾尽天下  阅读(142)  评论(0编辑  收藏  举报

导航