C. The Smallest String Concatenation

题目连接:

http://www.codeforces.com/contest/632/problem/C

Description

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.

Sample Input

4

abba

abacaba

bcd

er

Sample Output

abacabaabbabcder

Hint

题意

给你n个串,然后你要组合这n个串,使得n个串的字典序最小

题解:

写个CMP就好了~

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 5e4+5;
string s[maxn];
bool cmp(string a,string b)
{
string ab = a+b;
string ba = b+a;
return ab<ba;
}
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
cin>>s[i];
sort(s,s+n,cmp);
for(int i=0;i<n;i++)
cout<<s[i];
cout<<endl;
}

Educational Codeforces Round 9 C. The Smallest String Concatenation 排序的更多相关文章

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

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

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

  3. [Educational Codeforces Round 16]E. Generate a String

    [Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...

  4. Educational Codeforces Round 16 E. Generate a String dp

    题目链接: http://codeforces.com/problemset/problem/710/E E. Generate a String time limit per test 2 seco ...

  5. Educational Codeforces Round 8 C. Bear and String Distance 贪心

    C. Bear and String Distance 题目连接: http://www.codeforces.com/contest/628/problem/C Description Limak ...

  6. Educational Codeforces Round 16 E. Generate a String (DP)

    Generate a String 题目链接: http://codeforces.com/contest/710/problem/E Description zscoder wants to gen ...

  7. Educational Codeforces Round 40 I. Yet Another String Matching Problem

    http://codeforces.com/contest/954/problem/I 给你两个串s,p,求上一个串的长度为|p|的所有子串和p的差距是多少,两个串的差距就是每次把一个字符变成另一个字 ...

  8. Educational Codeforces Round 4 D. The Union of k-Segments 排序

    D. The Union of k-Segments   You re given n segments on the coordinate axis Ox and the number k. The ...

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

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

随机推荐

  1. sublime在搜索的时候排除js文件

    代码审计的时候sublime是一个神器.所以.... Ctrl + Shift + F /home/i3ekr/Desktop/coding/phpcms,*.php 这样就可以直接搜索所有的php文 ...

  2. %和format 细说

    Python中格式化字符串目前有两种阵营:%和format,我们应该选择哪种呢? 自从Python2.6引入了format这个格式化字符串的方法之后,我认为%还是format这根本就不算个问题.不信你 ...

  3. bootstrap-select属性

    # 参考:https://blog.csdn.net/zxl_langya/article/details/79247307 # bootstrap-select属性: <select mult ...

  4. 從 kernel source code 查出 版本號碼

    kernel/Makefile 1 VERSION = 4 2 PATCHLEVEL = 4 3 SUBLEVEL = 21 4 EXTRAVERSION = 5 NAME = Blurry Fish ...

  5. [New learn] 网络基础-网络操作

    代码:https://github.com/xufeng79x/NETOperation 1.简介 主要记录基本的网络操作步骤,get/post关系和区别和文件上传实现. 2.准备 需要服务器端,如果 ...

  6. Window Server 2008 R2 安装 Share Point 2013

    原文地址:http://www.cnblogs.com/jianyus/p/3631905.html

  7. 关于springMVC转换json出现的异常

    jackson-core-asl-1.9.0.jar,jackson-mapper-asl-1.9.0.jar两个包 并且在controller中有如下代码 @RequestMapping(value ...

  8. classpath中怎样一次性加入整个目录的jar文件

    linux可以通过shell来处理 1 2 3 for jar in $HOME/lib/*.jar; do     CLASSPATH=$CLASSPATH:$jar done          

  9. 前端读者 | 前端开发者调试面板vConsole

    来着微信团队开源的一个调试工具,[GitHub地址]https://github.com/Tencent/vConsole 一个轻量.可拓展.针对手机网页的前端开发者调试面板. 特性 查看 conso ...

  10. Aras Innovator DB备份与还原

    错误信息 确认到该问题是因为孤立帐号的问题,在解决孤立帐号之前,可以通过语句查看,另外,还原了DB后,系统不会自动创建原来的登陆帐号的,需要手动新增登陆帐号 #查看孤立帐号列表exec sp_chan ...