new criterion of sorting.
// 1038. Recover the Smallest Number.cpp: 主项目文件。 #include "stdafx.h" #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N=10003; const int Dmax=9; typedef struct Node{ char str[Dmax]; }Node; Node node[N]; int num[N]; bool cmp(Node m1,Node m2){ char *str1=new char[2*Dmax+1]; char *str2=new char[2*Dmax+1]; strcpy(str1,m1.str); strcat(str1,m2.str); strcpy(str2,m2.str); strcat(str2,m1.str); return strcmp(str1,str2)<0; } int main(){ int n; scanf("%d",&n); for(int i=0;i<n;i++) scanf("%s",node[i].str); sort(node,node+n,cmp); bool tag=false; for(int i=0;i<n;i++){ int notZero=0; if(!tag){ while(node[i].str[notZero]!='\0'){ if(node[i].str[notZero]!='0'){ tag=true; break; } notZero++; } } printf("%s",node[i].str+notZero); } if(!tag) printf("0"); printf("\n"); return 0; }