root • 2年前
using namespace std; int u[100001],u1[100001]; struct l{
char x1[21];
int x2[21];
}x[10001]; bool cmp(l a,l b){
int t=0,m=0;
memset(u,0,sizeof(u));
memset(u1,0,sizeof(u1));
int minn=0;
minn=min(strlen(a.x1),strlen(b.x1));
for(int i=0;i<minn;i++){
if(a.x2[i]!=b.x2[i]){
return a.x2[i]>b.x2[i];
}
}
for(int j=0;j<strlen(a.x1);j++){
u[++t]=a.x2[j];
}
for(int j=0;j<strlen(b.x1);j++){
u[++t]=b.x2[j];
}
for(int j=0;j<strlen(b.x1);j++){
u1[++m]=b.x2[j];
}
for(int j=0;j<strlen(a.x1);j++){
u1[++m]=a.x2[j];
}
for(int j=1;j<=m+t;j++){
if(u[j]!=u1[j]){
return u[j]>u1[j];
}
}
} int main(){
int s;
cin>>s;
for(int i=1;i<=s;i++){
scanf("%s",x[i].x1);
for(int j=0;j<strlen(x[i].x1);j++){
x[i].x2[j]=x[i].x1[j]-'0';
}
}
sort(x+1,x+s+1,cmp);
for(int i=1;i<=s;i++){
cout<<x[i].x1;
}
return 0;
}
评论:
请先登录,才能进行评论