1038 Recover the Smallest Number (30 分)
注:贪心
#include <stdio.h> #include <algorithm> #include <string> #include <iostream> using namespace std; const int maxn=10010; string z[maxn]; bool cmp(string a,string b) { return a+b<b+a; } int main () { int n,i; string ans=""; cin >>n; for (i=0;i<n;i++) cin >>z[i]; sort(z,z+n,cmp); for (i=0;i<n;i++) ans=ans+z[i]; while (ans.length()!=0&&ans[0]=='0') { ans.erase(ans.begin()); } if (ans.length()==0) printf ("0"); else printf ("%s",ans.c_str()); return 0; }