大佬教程收集整理的这篇文章主要介绍了PAT_A1038#Recover the Smallest Number,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
1 /* 2 Data: 2019-07-23 18:47:04 3 Problem: PAT_A1038#Recover the smallest number 4 AC: 16:22 5 6 题目大意: 7 给几个数,求拼成的最小数 8 */ 9 #include<cstdio> 10 #include<String> 11 #include<iostream> 12 #include<algorithm> 13 using namespace std; 14 const int M=1e4+10; 15 String s[M]; 16 17 bool cmp(String a,String b) 18 { 19 return a+b < b+a; 20 } 21 22 int main() 23 { 24 #ifdef ONLINE_JUDGE 25 #else 26 freopen("Test.txt","r",stdin); 27 #endif 28 29 int n; 30 scanf("%d",&n); 31 for(int i=0; i<n; i++) 32 cin >> s[i]; 33 sort(s,s+n,cmp); 34 String ans=""; 35 for(int i=0; i<n; i++) 36 ans += s[i]; 37 while(ans.size()>1 && ans[0]==‘0‘) 38 ans.erase(0,1); 39 cout << ans; 40 41 return 0; 42 }
以上是大佬教程为你收集整理的PAT_A1038#Recover the Smallest Number全部内容,希望文章能够帮你解决PAT_A1038#Recover the Smallest Number所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。