632C. The Smallest String Concatenation(注意 :stl sort函数坑点--- coredump问题 )
链接:http://codeforces.com/problemset/problem/632/C
思路:思路很快想到了,但是被sort坑了,对于sort的自定义比较函数,记住 对于相等的值一定要返回flase
附上别的大佬的验证:https://blog.csdn.net/xhu_eternalcc/article/details/52227644
1 #include<bits/stdc++.h> 2 using namespace std; 3 4 const int maxn = 5e4+5; 5 string s[maxn]; 6 bool cmp(string a,string b) 7 { 8 return a+b <= b+a; 9 } 10 int n; 11 int main() 12 { 13 scanf("%d",&n); 14 for(int i=1;i<=n;i++) 15 { 16 cin>>s[i]; 17 } 18 sort(s+1,s+1+n,cmp); 19 string ans; 20 for(int i=1;i<=n;i++)ans+=s[i]; 21 cout<<ans<<endl; 22 }