日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【Codeforces - 632C】The Smallest String Concatenation (对string巧妙排序)

發(fā)布時(shí)間:2023/12/10 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【Codeforces - 632C】The Smallest String Concatenation (对string巧妙排序) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題干:

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

4 abba abacaba bcd er

Output

abacabaabbabcder

Input

5 x xx xxa xxaa xxaaa

Output

xxaaaxxaaxxaxxx

Input

3 c cb cba

Output

cbacbc

?

解題報(bào)告:

類似于nyoj 1233這道題(這題需要處理大數(shù))。本題直接排序就好了。這題如果不用string的話,需要用Node結(jié)構(gòu)體存char [] ,然后對(duì)Node排序(用strcmp函數(shù)),不知道時(shí)間上會(huì)不會(huì)快一點(diǎn)?反正這個(gè)題用string類是300+ms左右。

AC代碼:

#include<cstring> #include<iostream> #include<algorithm> #include<cstdio> using namespace std; string s[50000 + 5]; int dp[1005][1005]; int len1,len2; bool cmp(string a,string b) {return a+b < b+a; } int main() {int n;cin>>n;for(int i = 1; i<=n; i++) {cin>>s[i];}sort(s+1,s+n+1,cmp); // for(int i = 1; i<=n; i++) { // cout << s[i]<<endl; // }for(int i = 1; i<=n; i++) {cout << s[i];}return 0 ; }

總結(jié)

以上是生活随笔為你收集整理的【Codeforces - 632C】The Smallest String Concatenation (对string巧妙排序)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。