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. centos7系统安装配置

    下载centos7 iso镜像 电脑里面本来有ubuntu系统,直接在u盘做好启动盘安装即可,选择手动分区(忘了),将原本ubuntu系统分区压缩200G.系统不要选择最小化,选择gnome的图形界面 ...

  2. 刷新SqlServer数据库中所有的视图

    ALTER PROCEDURE sp_refallview AS --刷新所有视图 DECLARE @ViewName VARCHAR(MAX); DECLARE @i INT; ; DECLARE ...

  3. sicily 1046. Plane Spotting

    1046. Plane Spotting Time Limit: 1sec    Memory Limit:32MB  Description Craig is fond of planes. Mak ...

  4. lsb_release查看当前系统的发行版信息

    Linux除了用uname -r查看系统版本信息外,还可以用lsb_release. 安装: yum install -y redhat-lsb-core 使用: lsb_release -a

  5. Canvas 高级

    一.Canvas 高级 1.变换--位移 translate(x, y) 2.变换-缩放 scale(xS, yS) 3.变换-旋转 rotate(弧度) 4.环境的保存和释放 save() rest ...

  6. [New learn] 手势

    1.简介 我们经常会在设备上查看图片等, 也会经常将图片通过手指的捏合打开来缩小和方法图片.这就是ios中的手势功能在起作用. 那么手势好像也是一种touch事件,那和UIResponder中定义的t ...

  7. Redis Cluster 集群使用(3)

    简介 Redis3.0版本之前,可以通过Redis Sentinel(哨兵)来实现高可用(HA),从3.0版本之后,官方推出了Redis Cluster,它的主要用途是实现数据分片(Data Shar ...

  8. elasticsearch批量删除(查询删除)

    注:delete by query只适用于低于elasticsearch2.0的版本(不包含2.0).有两种形式: 1.无请求体 curl -XDELETE 'localhost:9200/twitt ...

  9. 【python】if __name__ == '__main__'

    转载自:http://www.cnblogs.com/xuxm2007/archive/2010/08/04/1792463.html 当你打开一个.py文件时,经常会在代码的最下面看到if __na ...

  10. 升级PIP源

    pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple django