排序,水题
本题要点:
1、 定义两个 string a 和 b 之间的排序规则, 就是把 a, b 拼接起来,看看 ab 大还是 ba 大。
2、 sort 好之后,输出最大值即可。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const int MaxN = 22;
string str[MaxN];
int n;
bool cmp(string a, string b)
{
string s1 = a + b, s2 = b + a;
return s1 > s2;
}
int main()
{
cin >> n;
for(int i = 0; i < n; ++i)
cin >> str[i];
sort(str, str + n, cmp);
string ans = str[0] ;
for(int i = 1; i < n; ++i)
ans += str[i];
cout << ans << endl;
return 0;
}
/*
3
13 312 343
*/
/*
34331213
*/
/*
4
7 13 4 246
*/
/*
7424613
*/