C. The Smallest String Concatenation

题目连接:

http://www.codeforces.com/contest/632/problem/C

Description

You're given a list of n strings a1, a2, ..., an. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest.

Given the list of strings, output the lexicographically smallest concatenation.

Input

The first line contains integer n — the number of strings (1 ≤ n ≤ 5·104).

Each of the next n lines contains one string ai (1 ≤ |ai| ≤ 50) consisting of only lowercase English letters. The sum of string lengths will not exceed 5·104.

Output

Print the only string a — the lexicographically smallest string concatenation.

Sample Input

4

abba

abacaba

bcd

er

Sample Output

abacabaabbabcder

Hint

题意

给你n个串,然后你要组合这n个串,使得n个串的字典序最小

题解:

写个CMP就好了~

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 5e4+5;
string s[maxn];
bool cmp(string a,string b)
{
string ab = a+b;
string ba = b+a;
return ab<ba;
}
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
cin>>s[i];
sort(s,s+n,cmp);
for(int i=0;i<n;i++)
cout<<s[i];
cout<<endl;
}

Educational Codeforces Round 9 C. The Smallest String Concatenation 排序的更多相关文章

  1. Educational Codeforces Round 9 C. The Smallest String Concatenation —— 贪心 + 字符串

    题目链接:http://codeforces.com/problemset/problem/632/C C. The Smallest String Concatenation time limit ...

  2. Educational Codeforces Round 9 C. The Smallest String Concatenation(字符串排序)

    You're given a list of n strings a1, a2, ..., an. You'd like to concatenate them together in some or ...

  3. [Educational Codeforces Round 16]E. Generate a String

    [Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...

  4. Educational Codeforces Round 16 E. Generate a String dp

    题目链接: http://codeforces.com/problemset/problem/710/E E. Generate a String time limit per test 2 seco ...

  5. Educational Codeforces Round 8 C. Bear and String Distance 贪心

    C. Bear and String Distance 题目连接: http://www.codeforces.com/contest/628/problem/C Description Limak ...

  6. Educational Codeforces Round 16 E. Generate a String (DP)

    Generate a String 题目链接: http://codeforces.com/contest/710/problem/E Description zscoder wants to gen ...

  7. Educational Codeforces Round 40 I. Yet Another String Matching Problem

    http://codeforces.com/contest/954/problem/I 给你两个串s,p,求上一个串的长度为|p|的所有子串和p的差距是多少,两个串的差距就是每次把一个字符变成另一个字 ...

  8. Educational Codeforces Round 4 D. The Union of k-Segments 排序

    D. The Union of k-Segments   You re given n segments on the coordinate axis Ox and the number k. The ...

  9. codeforces 632C. The Smallest String Concatenation 排序

    题目链接 给出n个字符串, 将他们连在一起, 求连玩之后字典序最小的那种情况. 按a+b<b+a排序.... #include <iostream> #include <vec ...

随机推荐

  1. 关于$->aaa->bbb();的困惑

    第21行为什么可以调用test类的aa方法呢? 答:因为前一行(20)其已经被实例化了.所以现在的$this->obj其实可以相当于是一个对象. 20行和21行也可以写成如下 $xxoo = n ...

  2. 【Android framework】am命令启动Activity流程

    源码基于Android 4.4.   am start -W -n com.dfp.test/.TEstActivity -W:等目标Activity启动后才返回 -n:用于设置Intent的Comp ...

  3. 测试mysqldump 压缩率和时间消耗

    测试mysqldump 压缩率和时间消耗 实验总结: 从本次实验数据可以看出,mysqldump通过|gzip参数可以将导出文件压缩53%,同时耗时也普通非压缩模式的2.3倍. 数据库环境: #[ro ...

  4. 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6156 数位DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6156 题意:如题. 解法:数位DP,暴力枚举进制之后,就转化成了求L,R区间的回文数的个数,这个直接做 ...

  5. 2017多校第5场 HDU 6085 Rikka with Candies bitset

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6085 题意:存在两个长度为n,m的数组A,B.有q个询问,每个询问有一个数字k,可以得到Ai%Bj=k ...

  6. 转载: GIt远程操作详解

    Git远程操作详解   作者: 阮一峰 日期: 2014年6月12日 Git是目前最流行的版本管理系统,学会Git几乎成了开发者的必备技能. Git有很多优势,其中之一就是远程操作非常简便.本文详细介 ...

  7. hibernate连接Oracle rac

    连接方式与普通的数据库不一样.connection.url 中使用了LOAD-BALANCE = yes 要不然会报错 <hibernate-configuration> <sess ...

  8. hdu 1428(很好的一道题,最短路+记忆化搜索)

    漫步校园 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  9. python IDE的配置

    本人使用过的两款,系统环境ubuntukylin 15.04 jupyter 主要参考:ref1 和 ref2 遇到问题: error: [I 21:48:41.947 NotebookApp] Wr ...

  10. 关于多属性查找问题的sphinx解决方案

    需求描述 mysql中,每一个文档都有多个标签,查询时可以筛选一个标签也可以筛选同时拥有多个标签的文档. 数据示例 文档 标签 1 1,2,3,4,5 2 2,3,4,5,6 3 3,4,5,6,7 ...