zoukankan      html  css  js  c++  java
  • UVA 10602 EDITOR NOTTOOBAD

     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
    ",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

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

  • 相关阅读:
    栈和队列
    链表
    map
    二叉平衡树旋转
    二叉排序树详情
    红黑树详情
    查并集
    动态规划
    位操作
    字典树
  • 原文地址:https://www.cnblogs.com/ghostTao/p/4394115.html
Copyright © 2011-2022 走看看