C. The Smallest String Concatenation
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Examples
input
4
abba
abacaba
bcd
er
output
abacabaabbabcder
input
5
x
xx
xxa
xxaa
xxaaa
output
xxaaaxxaaxxaxxx
input
3
c
cb
cba
output
cbacbc
题意:给你n个字符串,输出字典序最小的排序;
思路:写个比较函数cmp(),sort一下再输出就好了;
AC代码:
#include <bits/stdc++.h>
using namespace std;
const int N=1e4+4;
string str[6*N];
int n;
int cmp(string x,string y)
{
return x+y<y+x;
}
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++)
{
cin>>str[i];
}
sort(str,str+n,cmp);
for(int i=0;i<n;i++)
{
cout<<str[i];
}
return 0;
}

codeforces 632C C. The Smallest String Concatenation(sort)的更多相关文章

  1. CodeForces 632C The Smallest String Concatenation//用string和sort就好了&&string的基础用法

    Description You're given a list of n strings a1, a2, ..., an. You'd like to concatenate them togethe ...

  2. codeforces 632C The Smallest String Concatenation

    The Smallest String Concatenation 题目链接:http://codeforces.com/problemset/problem/632/C ——每天在线,欢迎留言谈论. ...

  3. Educational Codeforces Round 9 C. The Smallest String Concatenation 排序

    C. The Smallest String Concatenation 题目连接: http://www.codeforces.com/contest/632/problem/C Descripti ...

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

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

  5. 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 ...

  6. C. The Smallest String Concatenation

    C. The Smallest String Concatenation time limit per test 3 seconds memory limit per test 256 megabyt ...

  7. C. The Smallest String Concatenation-C++sort排序~~

    C. The Smallest String Concatenation time limit per test 3 seconds memory limit per test 256 megabyt ...

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

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

  9. [Swift]LeetCode988. 从叶结点开始的最小字符串 | Smallest String Starting From Leaf

    Given the root of a binary tree, each node has a value from 0 to 25 representing the letters 'a' to  ...

随机推荐

  1. 在linux下解压缩 tar.gz文件

    解压:tar -xzvf 文件名 压缩 tar czf xx.tar.gz xxxx文件名

  2. 笔试真题解析 ALBB-2015 算法project师实习生机试

    1.用十进制计算30!(30的阶乘),将结果转换成3进制进行表示的话,该进制下的结果末尾会有____个0. [解析] 计算N.下3进制结果末尾有多少个0,事实上就是计算3进制中的3被进位多少次,仅仅要 ...

  3. 用C#来学习唐诗三百首和全唐诗

    Begin 最近把项目做完了,闲来无事,就想做点好玩的事情,刚好前几天下载了[唐诗三百首]和[全唐诗]这两个txt文件,正好用C#来整理一下. 然后导出QData格式,可以给其他软件读取. 以后弄个开 ...

  4. jquery获取页面iframe内容

    //取得整个HTML格式 var f = $(window.frames["ReportIFrame"].document).contents().html(); 或者 $(&qu ...

  5. IM测试功能点

    测试前的总结: 1. 对象 对象就是聊天的联系人,包括个人账号,公共号,机构号,群组等. 2. 对象的属性 就是这些联系人的各个特征. 个人主页(头像,昵称,签名,管理的群,管理的轻应用,2维码... ...

  6. 【BZOJ5016】[Snoi2017]一个简单的询问 莫队

    [BZOJ5016][Snoi2017]一个简单的询问 Description 给你一个长度为N的序列ai,1≤i≤N和q组询问,每组询问读入l1,r1,l2,r2,需输出 get(l,r,x)表示计 ...

  7. 【BZOJ1778】[Usaco2010 Hol]Dotp 驱逐猪猡 期望DP+高斯消元

    [BZOJ1778][Usaco2010 Hol]Dotp 驱逐猪猡 Description 奶牛们建立了一个随机化的臭气炸弹来驱逐猪猡.猪猡的文明包含1到N (2 <= N <= 300 ...

  8. Collective Mindsets (easy)(逻辑题)

    Collective Mindsets (easy) Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d &am ...

  9. nginx学习之压缩解压篇(七)

    1.简介 压缩响应可以减少传输数据的大小,节省带宽.但过多的压缩会造成很大的处理开销.在发送给客户端之前,nginx会对响应做压缩,但是如果后端服务器已经 压缩过了,nginx就不再压缩. 2.开启压 ...

  10. 2017-2018-1 20179209《Linux内核原理与分析》第九周作业

    理解进程调度时机 进程调度时机 中断处理过程(包括时钟中断.I/O中断.系统调用和异常)中,直接调用schedule(),或者返回用户态时根据need_resched标记调用schedule(): 内 ...