题干:

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

解题报告:

类似于nyoj 1233这道题(这题需要处理大数)。本题直接排序就好了。这题如果不用string的话,需要用Node结构体存char [] ,然后对Node排序(用strcmp函数),不知道时间上会不会快一点?反正这个题用string类是300+ms左右。

AC代码:

#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
string s[50000 + 5];
int dp[1005][1005];
int len1,len2;
bool cmp(string a,string b) {return a+b < b+a;
}
int main()
{int n;cin>>n;for(int i = 1; i<=n; i++) {cin>>s[i];}sort(s+1,s+n+1,cmp);
//  for(int i = 1; i<=n; i++) {
//      cout << s[i]<<endl;
//  }for(int i = 1; i<=n; i++) {cout << s[i];}return 0 ;
}

【Codeforces - 632C】The Smallest String Concatenation (对string巧妙排序)相关推荐

  1. overloading 重载 String concatenation BlueJ 的 Code Pad

    Overloading 重载 这是一个打票机 import lang.stride.*;public class TicketMachine {/* The price of a ticket fro ...

  2. oracle11g ora 29927,listagg函数 ORA-01489 result of string concatenation is too long的解决办法 【博森瑞】...

    listagg函数 ORA-01489: result of string concatenation is too long的解决办法 概述 listagg 函数是Oracle 11g推出的一个分组 ...

  3. oracle ora32771,listagg函数 ORA-01489: result of string concatenation is too long的解决办法

    概述 listagg函数是Oracle 11g推出的一个分组函数,可以将字符串按分组连接起来. SQL> select deptno ,listagg(ename,'->') within ...

  4. Codeforces Round #656 (Div. 3) D. a-Good String

    Codeforces Round #656 (Div. 3) D. a-Good String 题目链接 You are given a string s[1-n] consisting of low ...

  5. 【CodeForces - 1084C】The Fair Nut and String(思维,组合数学)

    题干: The Fair Nut found a string ss. The string consists of lowercase Latin letters. The Nut is a cur ...

  6. 请别再拿“String s = new String(xyz);创建了多少个String实例”来面试了吧---转

    http://www.iteye.com/topic/774673 羞愧呀,不知道多少人干过,我也干过,面壁去! 这帖是用来回复高级语言虚拟机圈子里的一个问题,一道Java笔试题的.  本来因为见得太 ...

  7. 美团面试题:String s = new String(111)会创建几个对象?

    点击关注公众号,Java干货及时送达 来源:blog.csdn.net/o9109003234/article/details/109523691 String不可变吗? public class A ...

  8. 工作10年后,再看String s = new String(xyz) 创建了几个对象?

    点击上方蓝色"方志朋",选择"设为星标" 回复"666"获取独家整理的学习资料! 转自:艾小仙 这个问题相信每个学习java的同学都不陌生, ...

  9. The constructor JedisPool(GenericObjectPoolConfig, String, int, int, String) refers to the missing t

    想学习学习redis缓存技术,于是到网上copy到了一些代码,粘贴到ecplise上面,但是发现代码总是报错 The constructor JedisPool(GenericObjectPoolCo ...

最新文章

  1. APUE 配置(Fedora)
  2. java include 传递对象_变量的值传递,地址引用(和对象成员变量、局部变量创建和初始化的内存机制)...
  3. putty和Xming server 结合完美在windows下显示linux GUI程序
  4. 【Python】挑战SQL:图解Pandas的数据合并merge
  5. 负载测试工具Ripplet
  6. s2sh删掉原本的s2sh project capabilities后重新添加它们
  7. C语言之字符串探究(八):strchr、strstr、strtok
  8. 重写方法,重载方法,虚方法和抽象方法的使用
  9. COSCon'20 Apache Roadshow- China 精彩收官 | 数据篇
  10. Delphi 下用Windows API 创建窗体
  11. 有哪些开源的小程序商城源码?
  12. VHDL实验-实现一位全加器
  13. 计算机应用基础课件教学大赛,全国“XX杯”说课大赛计算机应用基础类优秀作品:设置IP地址教学课件.ppt...
  14. ADMM 大规模变量优化
  15. 状态反馈不改变系统传递函数零点的证明
  16. 多线程爬取图片(生产者-消费者模式)
  17. 绝招:技术专家教你打造个性域名!
  18. 最值得收藏的电脑使用习惯, 让你使用电脑的效率轻松提升数倍(持续更新中)
  19. H5前端输入和展示 表情 三种解决方案
  20. pageBean的介绍

热门文章

  1. [hackinglab][CTF][注入关][2020] hackinglab 注入关 writeup
  2. Codeforces Round #413 C-Fountains 树状数组
  3. android 复制字符串,Cocos2dx 复制文本到剪切板(Android 和 ios)
  4. snmp获取交换机日志_日志审计系统和数据库审计系统的区别
  5. threejs渲染器剔除模式
  6. 怎么在同一页中分页_分库分表业界难题,跨库分页的几种常见方案
  7. oracle数sqlplus,sqlplus查询oracle数据库数据容量
  8. Linux Kbuild文档 2
  9. DNW应用程序错误,DNW错误问题解决
  10. 设计模式C++实现 ——状态模式