新疆大學OJ(ACM) 1047: string 字符串排序
阿新 • • 發佈:2017-10-20
pac out map 所有 ring bsp 時間限制 () 字符串長度
1047: string
時間限制: 1 Sec 內存限制: 128 MB題目描述
有n個字符串字符串n<=50000,把所有字符串串起來,得到一個字典序最小的字符串。輸入
輸入第一行是一個整數n,接下來的n行包含n串字符串,字符串長度小於50。輸出
輸出一行字符串s,是所有可能組成的字符串中字典序排序最小的字符串。樣例輸入
4 abc xyz hij qqqq
樣例輸出
abchijqqqqxyz
提示
input
5
x
xx
xxa
xxaa
xxaaa
output
xxaaaxxaaxxaxxx
排序即可:
#include <iostream> #include<string.h> #include <string> #include <map> #include <algorithm> using namespace std; typedef long long ll; string a[50010]; 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 >> a[i]; sort(a,a+n,cmp); for(int i = 0;i < n; i++) cout << a[i]; cout << endl; return 0; } // writen by zhangjiuding
新疆大學OJ(ACM) 1047: string 字符串排序