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. Tornado 目录

    第一章:引言 1.1 Tornado是什么? 1.1.1 Tornado入门 1.1.2 社区和支持 1.2 简单的Web服务 1.2.1 Hello Tornado 1.2.1.1 参数handle ...

  2. centos rar 文件打开办法

    http://hi.baidu.com/nmxiaoxin/item/7642a139918a95677d034b6a Centos下解压rar.zip文件的方法 ============zip文件的 ...

  3. 64_m2

    mimetic-devel-0.9.8-7.fc26.i686.rpm 12-Feb-2017 05:40 288474 mimetic-devel-0.9.8-7.fc26.x86_64.rpm 1 ...

  4. [转载]Python: 你不知道的 super

    原文出处: geekvi super() 的入门使用 在类的继承中,如果重定义某个方法,该方法会覆盖父类的同名方法,但有时,我们希望能同时实现父类的功能,这时,我们就需要调用父类的方法了,可通过使用  ...

  5. memcached和redis区别

    Memcached:是高性能分布式内存缓存服务器,本质是一个内存 key-value 数据库,但不支持数据持久化,服务器关闭后,数据全丢失.只支持 key-value 结构. Redis:将大部分数据 ...

  6. ArcGIS Server 基于Token安全验证

    写在前面:只使用token并不能起到安全验证的作用,ArcGIS Server文件夹的权限是开放的,我们不需要登录Server平台即可访问服务,所以我们应该将Token验证和文件夹的安全性结合起来使用 ...

  7. MySQL乐观锁

    MySQL悲观锁是依靠数据库的锁机制来实现,以实现最大程度上的独占性.但由于现代的web系统一般都是高并发的,所以悲观锁在这样的情况下的适用性不高,所以我们有了和悲观锁相对应的乐观锁. 乐观锁,是说假 ...

  8. js获取鼠标的位置

    <!doctype html><html><head><meta charset="utf-8"><title>获取鼠标 ...

  9. django “如何”系列5:如何编写自定义存储系统

    如果你需要提供一个自定义的文件存储-一个常见的例子便是在远程系统上存储文件-你可以通过定义一个自己的存储类来做这件事情,你将通过一下步骤: 你自定义的存储系统一定是django.core.files. ...

  10. window,getComputedStyle,letter-spacing

       js 拿到element的css样式    window.getComputedStyle(ele,[pseuso)    比如想拿到一个element的背景色 window.getComput ...