码迷,mamicode.com
首页 > 其他好文 > 详细

UVA 10602 EDITOR NOTTOOBAD

时间:2015-04-05 15:49:56      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:

技术分享
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 #include <vector>
 6 #define sc(x)  scanf("%d", &x)
 7 #define pf(x)    printf("%d\n",x)
 8 #define FOR(i,b,e)    for(i=b;i<=e;i++)
 9 #define FOR1(i,b,e)    for(i=b;i>=e;i--)
10 #define CL(x,y)      memset(x,y,sizeof(x))
11 using namespace std;
12 struct node
13 {
14     string str;
15 };
16 bool cmp(const node &a, const node &b)
17 {
18     return a.str < b.str;//ÉýÐò 
19 }
20 vector <node> v;
21 int T, ans, n;
22 string s;
23 int main()
24 {
25     sc(T);
26     while(T--)
27     {
28         int i, j;
29         v.clear();
30         sc(n);
31         ans = 0;
32         FOR(i,0,n-1)
33         {
34             cin >> s;
35             v.push_back(node{s});
36         }
37         sort(v.begin(), v.end(), cmp);
38         FOR(i,0,n-1)
39         {
40             if(i == 0)
41                 ans += v[i].str.length();
42             else
43             {
44                 for(j = 0; j < v[i].str.length() && j < v[i-1].str.length(); )
45                     if(v[i].str[j] == v[i-1].str[j])
46                         j++;
47                     else
48                         break;
49                 ans += v[i].str.length() - j;
50             }
51         }
52         pf(ans);
53         FOR1(i,n-1,0)
54             cout << v[i].str << endl;
55     }
56     return 0;
57 }
View Code

这题目考虑到输入最少的按键,需要先排序,再对字符串之间进行安排

UVA 10602 EDITOR NOTTOOBAD

标签:

原文地址:http://www.cnblogs.com/tyx0604/p/4394115.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!