在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
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 Input
4 Output
abacabaabbabcder Input
5 Output
xxaaaxxaaxxaxxx Input
3 Output
cbacbc 1 #include <stdio.h> 2 #include <string.h> 3 #include <iostream> 4 #include <algorithm> 5 #include <string> 6 using namespace std; 7 struct node 8 { 9 string str; 10 11 }; 12 node str1[50010]; 13 bool cmp(node a,node b) 14 { 15 return a.str+b.str<b.str+a.str; 16 } 17 int main() 18 { 19 int n; 20 while(scanf("%d",&n)!=EOF) 21 { 22 for(int i=1;i<=n;i++) 23 { 24 cin>>str1[i].str; 25 } 26 sort(str1+1,str1+1+n,cmp); 27 for(int i=1;i<=n;i++) 28 cout<<str1[i].str; 29 printf("\n"); 30 } 31 return 0; 32 } 这个时候说一下string的用法 注意是#include <string>而不是#include <cstring> a) string s; //生成一个空字符串s 2.字符串操作函数 |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论