Codeforces 632C The Smallest String Concatenation 【string】

来源:互联网 发布:在家做淘宝客服兼职 编辑:程序博客网 时间:2024/05/17 22:03

C. The Smallest String Concatenation
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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
4abbaabacababcder
output
abacabaabbabcder
input
5xxxxxaxxaaxxaaa
output
xxaaaxxaaxxaxxx
input
3ccbcba
output
cbacbc


题意:给你n个短串,让你组成一个字典序最小的串。


思路:string随便搞。


AC代码:


#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <map>#include <string>#include <vector>#include <queue>#include <stack>#define CLR(a, b) memset(a, (b), sizeof(a))#define ll o<<1#define rr o<<1|1using namespace std;typedef long long LL;const int MOD = 1e9+7;const int MAXN = 5*1e4+10;const int INF = 0x3f3f3f3f;void add(LL &x, LL y) {x += y; x %= MOD;}string str[MAXN];bool cmp(string a, string b){    return a + b < b + a;}int main(){    int n; cin >> n;    for(int i = 0; i < n; i++) cin >> str[i];    sort(str, str+n, cmp);    for(int i = 0; i < n; i++) cout << str[i];    cout << endl;    return 0;}


0 0
原创粉丝点击