这道题其实说白了就是处理sort的cmp函数,其实就是比较两个连起来的话哪个放前面会更大一些,
思路只要想通就很好实现了
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std;
int n;
string s[100];
bool cmp(string a, string b)
{
string c, d;
c = a+b;
d = b+a;
return c.compare(d)>0;
}
int main()
{
//freopen("a.txt", "r", stdin);
while(scanf("%d", &n)&&n)
{
for(int i = 0;i < n;i++)
{
cin>>s[i];
}
sort(s, s+n, cmp);
for(int i = 0;i < n;i++)
{
cout << s[i];
}
cout << endl;
}
return 0;
}
2252

被折叠的 条评论
为什么被折叠?



