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. android事件拦截处理机制具体解释

    前段时间刚接触过android手机开发.对它的事件传播机制不是非常了解,尽管网上也查了相关的资料,可是总认为理解模模糊糊,似是而非,于是自己就写个小demo測试了一下. 总算搞明确了它的详细机制.写下 ...

  2. 转载 OS js oc相互调用(JavaScriptCore) ---js调用iOS ---js里面直接调用方法

    OS js oc相互调用(JavaScriptCore)   接着上节我们讲到的iOS调用js 下来我们使用js调用iOS js调用iOS分两种情况 一,js里面直接调用方法 二,js里面通过对象调用 ...

  3. lua(仿类)

    Account = { balance = } function Account:deposit(v) self.balance = self.balance + v end function Acc ...

  4. [原创]将本地代码共享到github的操作步骤

    将本地代码共享到github的操作步骤 本地代码目录执行如下命令,初始化为git仓库. git init 到github上新建一个仓库,假设为https://github.com/sky0014/sk ...

  5. 第三课 nodejs读取文件

    //引入文件操作模块var fs = require('fs'); //读取文件 使用 回调函数 utf-8编码读取 a.txt在当前文件目录fs.readFile('a.txt','UTF-8',f ...

  6. 2.二级接口ListableBeanFactory

    这个随笔主要讲的是ListableBeanFactory package org.springframework.beans.factory; import java.lang.annotation. ...

  7. iOS 字符串截取,将字符串中用括号包含的内容去除

    //去除字符串中用括号括住的位置 -(NSString *)handleStringWithString:(NSString *)str{ NSMutableString * muStr = [NSM ...

  8. 4.对urls.py的解释

    解释: 路由配置文件(URL分发器),它的本质是URL模式以及要为该URL模式调用的视图函数之间的映射表.就是以这种方式告诉Django对于每个URL的处理类.Django启动的时候回去加载urls. ...

  9. 用Visual Studio编辑Linux代码

    估计很多人都是用惯了Visual Studio的主,怎么也不适应Linux的一套编辑器,比如vim.source insight这些东西,可视化的eclipse效果还好点,但一般以远程共享一台Linu ...

  10. awk 字符串函数

    awk 提供了许多强大的字符串函数,见下表: awk 内置字符串函数 gsub(r,s) 在整个 $0 中用 s 替代 r gsub(r,s,t) 在整个 t 中用 s 替代 r index(s,t) ...