日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

pat1038. Recover the Smallest Number (30)

發布時間:2025/4/9 编程问答 15 豆豆
生活随笔 收集整理的這篇文章主要介紹了 pat1038. Recover the Smallest Number (30) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1038. Recover the Smallest Number (30)

時間限制 400 ms 內存限制 65536 kB 代碼長度限制 16000 B 判題程序 Standard 作者 CHEN, Yue

Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given {32, 321, 3214, 0229, 87}, we can recover many numbers such like 32-321-3214-0229-87 or 0229-32-87-321-3214 with respect to different orders of combinations of these segments, and the smallest number is 0229-321-3214-32-87.

Input Specification:

Each input file contains one test case. Each case gives a positive integer N (<=10000) followed by N number segments. Each segment contains a non-negative integer of no more than 8 digits. All the numbers in a line are separated by a space.

Output Specification:

For each test case, print the smallest number in one line. Do not output leading zeros.

Sample Input: 5 32 321 3214 0229 87 Sample Output: 22932132143287

提交代碼

?

?

學習網址:http://blog.csdn.net/sinat_29278271/article/details/48047877

里面的傳遞性是可以證明的

?

1 #include<cstdio> 2 #include<algorithm> 3 #include<iostream> 4 #include<cstring> 5 #include<queue> 6 #include<vector> 7 #include<cmath> 8 #include<string> 9 using namespace std; 10 vector<string> v; 11 bool cmp(string a,string b){ 12 return a+b<b+a; 13 } 14 int main(){ 15 //freopen("D:\\INPUT.txt","r",stdin); 16 int n,i; 17 scanf("%d",&n); 18 string s; 19 for(i=0;i<n;i++){ 20 cin>>s; 21 v.push_back(s); 22 } 23 sort(v.begin(),v.end(),cmp); 24 s=""; 25 for(i=0;i<n;i++){ 26 s=s+v[i]; 27 } 28 for(i=0;i<s.length();i++){ 29 if(s[i]!='0'){ 30 break; 31 } 32 } 33 34 if(i==s.length()){ 35 printf("0\n"); 36 } 37 else{ 38 for(;i<s.length();i++){ 39 cout<<s[i]; 40 } 41 cout<<endl; 42 } 43 return 0; 44 }

?

轉載于:https://www.cnblogs.com/Deribs4/p/4770206.html

總結

以上是生活随笔為你收集整理的pat1038. Recover the Smallest Number (30)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。