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. php != 和 !== 的区别

    == and != do not take into account the data type of the variables you compare. So these would all re ...

  2. JAVA读文件和写文件的的代码模版

    有的时候经常为真么读写文件最合理发愁,因为JAVA提过读写文件的方式太多了(C更甚至,fopen & open又有多少人傻傻分不去,更别说ReadFile了). 这里个人绝对比较好的写法,仅供 ...

  3. Android 浏览器文本垂直居中问题

    问题描述 在开发中,我们常使用 line-height 属性来实现文本的垂直居中,但是在安卓浏览器渲染中有一个常见的问题,就是对于小于12px的字体使用 line-height 属性进行垂直居中的时候 ...

  4. iOS 生命周期 -init、viewDidLoad、viewWillAppear、viewDidAppear、viewWillDisappear、viewDidDisappear 区别和用途

    iOS视图控制对象生命周期-init.viewDidLoad.viewWillAppear.viewDidAppear.viewWillDisappear.viewDidDisappear的区别及用途 ...

  5. Largest Rectangle in a Histogram (最大子矩阵)

    hdu 1506 A histogram is a polygon composed of a sequence of rectangles aligned at a common base line ...

  6. Card Collector

    In your childhood, do you crazy for collecting the beautiful cards in the snacks? They said that, fo ...

  7. PBR探索

    原理 根据能量守恒,以及一系列光照原理得出微表面BRDF(Bidirectional Reflectance Distribution Function)公式 // D(h) F(v,h) G(l,v ...

  8. 我的Android进阶之旅------>Android中StateListDrawable支持的状态

    Android中StateListDrawable支持的状态 android:state_active 代表是否处于激活状态 android:state_checked  代表是否处于已勾选状态 an ...

  9. spring bean标签常用属性

    一.id属性 其名称,可以是任意名称,但不能包含特殊符号. 根据id得到配置对象. 二.class属性 创建对象所在的类名称 三.name属性 功能和id属性一样,但name属性值可以包含特殊属性 四 ...

  10. Linux安装samba

    说明:samba的作用是实现window环境和linux环境下的文件共享,相当于window里的网络邻居,有一定的价值,但是随着时代的发展,现在用各种ssh软件登录linux实现文件共享和传输的场景越 ...