The Smallest String Concatenation

CodeForces - 632C

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 stringai (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.

Example
Input
4
abba
abacaba
bcd
er

Output
abacabaabbabcder

Input
5
x
xx
xxa
xxaa
xxaaa

Output
xxaaaxxaaxxaxxx

Input
3
c
cb
cba

Output
cbacbc

嗯 题目的意思就是按照字典序列从小到大排序 是字符串

转载来自http://blog.csdn.net/liuke19950717/article/details/51073998

这个是字符串 都是利用sort()92ms

#include<algorithm>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define maxn 500500
struct node
{char kk[500];
}str[maxn];
bool cmp(node a,node b)
{return strcmp(strcat(a.kk,b.kk),strcat(b.kk,a.kk))<0;
}
int main()
{int n,i;scanf("%d",&n);for(i=0;i<n;i++)scanf("%s",str[i].kk);sort(str,str+n,cmp);for(i=0;i<n;i++)printf("%s",str[i].kk);putchar('\n');return 0;
}

这个是利用string嗯 我也不会还没有学c++

300多ms

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
using namespace std;
int cmp(string a,string b)
{return a+b<b+a;
}
int main()
{int n;scanf("%d",&n);string x[50005];for(int i=1;i<=n;i++)cin >> x[i];sort(x+1,x+n+1,cmp);for(int i=1;i<=n;i++)cout << x[i];printf("\n");return 0;
}

C - The Smallest String Concatenation CodeForces - 632C(按字典序列排列 )string或者数组相关推荐

  1. 【Codeforces - 632C】The Smallest String Concatenation (对string巧妙排序)

    题干: You're given a list of n strings a1, a2, ..., an. You'd like to concatenate them together in som ...

  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. overloading 重载 String concatenation BlueJ 的 Code Pad

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

  4. codeforces 1660 C. Get an Even String

    codeforces 1660 C. Get an Even String 题目链接 贪心解法: 这里的做法是对于一对连续的字符,从左到右扫描,每次都要把当前的和离他最近的那个字符进行匹配.这个操作可 ...

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

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

  6. A Perfectly Balanced String?(Codeforces Round #785 (Div. 2))

    A Perfectly Balanced String? Let's call a string s perfectly balanced if for all possible triplets ( ...

  7. java string改变的影响_为什么Java的string类要设成immutable(不可变的)

    最流行的Java面试题之一就是:什么是不可变对象(immutable object),不可变对象有什么好处,在什么情况下应该用,或者更具体一些,Java的String类为什么要设成immutable类 ...

  8. android byte[] 转string 好多问号_java程序员面试遇到string题如何不凉?

    原标题:java程序员面试遇到string题如何不凉? 最近看到好多同学都在储备面试知识,以备来年轻松应对面试官,拿到心仪offer,之前好多同学反映遇到string,都只能送给自己一首凉凉.别凉,今 ...

  9. c++ string 堆还是栈_5个刁钻的String面试题解析

    1.判定定义为String类型的st1和st2是否相等,为什么? public class Demo2_String { public static void main(String[] args) ...

  10. string和C语言字符串之间的相互转换以及string常用函数

    #include <iostream> #include <vector> #include <algorithm> #include <string> ...

最新文章

  1. Activity创建
  2. 转PHP5+APACHE2.2配置
  3. Thrown KeeperErrorCode = Unimplemented for /services exception
  4. CVPR14与图像视频检索相关的论文
  5. 在linux下搭建jira+svn[原创]
  6. Mysql 中根据条件排序获取排名
  7. python机器学习案例系列教程——极大似然估计、EM算法
  8. [windows+cocos2dx]CCSprite精灵类
  9. 【安装包】VC++6.0
  10. :visible.sync 的作用
  11. 解决delphi7在win10上安装后无法正常使用的问题
  12. 使用预计算实时全局光照优化照明-项目介绍
  13. 6、深思数盾加密狗使用小记
  14. Android关于微博发表微博时@好友后删除@的好友的功能实现
  15. 2010-2019中国企业所有跨国并购数据
  16. 办公邮箱怎么选,邮箱选哪个更好用?
  17. 印象笔记好还是有道云笔记好_有道云笔记和印象笔记哪个好?
  18. 《反脆弱:从不确定性中获益》
  19. 用Java抓取RSS生成Mobi文件发送到Kindle
  20. 【求职】程序员如何应对面试?保姆级步骤让你完美面试

热门文章

  1. fd抓包数据类型_fiddler——抓包中的王者
  2. python中正确的赋值语句_在Python中使用赋值表达式时,如何完成赋值语句“x=y:=f(x)”?...
  3. css实现在一行显示多余部分显示省略号
  4. 【python】编程语言入门经典100例--23
  5. Oracle_11g_R2数据库在Windows_Server_2008_R2企业版中安装
  6. Android应用程序组件Content Provider的启动过程源代码分析(5)
  7. GPO组策略 权限处理之原则
  8. Git ssh_key生成方法
  9. [2019.2.28]BZOJ4033 [HAOI2015]树上染色
  10. 洛谷P4867 Gty的二逼妹子序列(莫队+树状数组)