首页 > 其他 > 详细

HDU5427

时间:2015-09-06 10:56:44      阅读:361      评论:0      收藏:0      [点我收藏+]
 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 }

 

HDU5427

原文:http://www.cnblogs.com/loveprincess/p/4784818.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!