大意不再赘述。
思路:这可以用到C++中STL的排序与重载,技巧性比较强,有点贪心的味道在里面。
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
const int MAXN = 60;
string str[MAXN];
int n;
int cmp(string a, string b)
{
return a + b > b + a;
}
void solve()
{
for(int i = 1; i <= n; i++) cin>>str[i];
sort(str+1, str+n+1, cmp);
for(int i = 1; i <= n; i++) cout<<str[i];
printf("\n");
}
int main()
{
while(scanf("%d", &n) && n)
{
solve();
}
return 0;
}