题目连接:https://www.patest.cn/contests/pat-a-practise/1038
这道题,无语了……参考了他人的代码
1 #include<stdio.h> 2 #include<algorithm> 3 #include<vector> 4 #include<string> 5 #include<iostream> 6 7 using namespace std; 8 int cmp(string a,string b) 9 { 10 return a+b<b+a; 11 } 12 13 int main() 14 { 15 int N,i; 16 vector<string>num; 17 scanf("%d",&N); 18 string tmp; 19 for (i=0;i<N;i++) 20 { 21 cin>>tmp; 22 num.push_back(tmp); 23 } 24 sort(num.begin(),num.end(),cmp); 25 26 string ans; 27 int non=-1; 28 for (i=0;i<num.size();i++)ans+=num[i]; 29 for (i=0;i<ans.size();i++) 30 { 31 if (ans[i]!='0') 32 { 33 non=i; 34 break; 35 } 36 } 37 if (non==-1)printf("0 "); 38 else 39 { 40 ans=ans.substr(non); 41 cout<<ans<<endl; 42 } 43 return 0; 44 }