牛客网--数串

题目链接: https://www.nowcoder.com/practice/a6a656249f404eb498d16b2f8eaa2c60?tpId=85&&tqId=29898&rp=1&ru=/activity/oj&qru=/ta/2017test/question-ranking

解题思路: 对于字符串a,b比较a+b和b+a的大小,然后排序。

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 const int MAXN = 100005;
 5 string s[MAXN];
 6 int n;
 7 int cmp(string a, string b)
 8 {
 9     return a+b > b+a;
10 }
11 
12 int main()
13 {
14     while (cin>>n)
15     {
16         for (int i = 1; i <= n; ++i)
17         {
18             cin>>s[i];
19         }
20         sort(s+1, s+1+n, cmp);
21         for (int i = 1; i <= n; ++i)
22         {
23             cout<<s[i];
24         }
25         cout<<endl;
26     }
27     return 0;
28 }

 

posted @ 2018-04-16 22:50  只会一点暴力  阅读(169)  评论(0编辑  收藏  举报