C:
#include?<stdio.h>
#include?<stdlib.h>
int?MyStrCmp(const?void*?lhs,?const?void*?rhs)
{
const?char*?a?=?(const?char*)lhs;
const?char*?b?=?(const?char*)rhs;
while(1)
{
if(*a?!=?*b)
return?*a?-?*b;
while(*a?&&?*b?&&?*a?==?*b)
++a,?++b;
if(!(*a)?&&?!(*b))
return?0;
if(!*b)
b?=?(const?char*)rhs;
else?if(!*a)
a?=?(const?char*)lhs;
}
}
int?LexicalCmp(const?void*?lhs,?const?void*?rhs)
{
static?char?BufLhs[16],?BufRhs[16];
sprintf(BufLhs,?"%d",?*(const?int*)lhs);
sprintf(BufRhs,?"%d",?*(const?int*)rhs);
return?MyStrCmp(BufRhs,?BufLhs);
}
int?main()
{
int?n,?*seq;
scanf("%d",?&n);
seq?=?(int*)malloc(n?*?sizeof(int));
for(int?i?=?0;?i?<?n;?++i)
scanf("%d",?&seq[i]);
qsort(seq,?n,?sizeof(int),?LexicalCmp);
for(int?i?=?0;?i?<?n;?++i)
printf("%d",?seq[i]);
free(seq);
return?0;
}
C++:
#include?<iostream>
#include?<string>
#include?<algorithm>
#include?<vector>
#include?<iterator>
using?namespace?std;
bool?MyStrCmp(const?string&?s1,?const?string&?s2)
{
return?s1?+?s2?>?s2?+?s1;
}
int?main()
{
vector<string>?v;
string?str;
while(cin.peek()?!=?'\n'?&&?cin?>>?str?)
v.push_back(str);
sort(v.begin(),?v.end(),?MyStrCmp);
copy(v.begin(),?v.end(),?ostream_iterator<string>(cout));
}