麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

1038. Recover the Smallest Number (30)

2019-11-14 11:20:39
字體:
供稿:網(wǎng)友

題目鏈接:https://www.patest.cn/contests/pat-a-PRactise/1038 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

#include<cstdio>#include<iostream>#include<string>#include<cstring>#include<algorithm>using namespace std;const int maxn=10010;string seg[maxn];bool cmp(string a,string b){ return a+b<b+a;//如{"321","32"},"32"<"321",但32321>32132,因此不能直接return a<b,應(yīng)該return a+b<b+a; }int main(){ int n; scanf("%d",&n); for(int i=0;i<n;i++){ cin>>seg[i]; } sort(seg,seg+n,cmp); string ans; for(int i=0;i<n;i++){ ans+=seg[i]; } while(ans.size()!=0&&ans[0]=='0'){ ans.erase((ans.begin())); } if(ans.size()==0) cout<<0; else cout<<ans; return 0;}
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 天天操天天看 | 亚洲福利视频52 | 欧美人xx | 日本不卡一区二区在线观看 | 免费在线观看中文字幕 | 久久99国产视频 | 亚洲精品一区国产精品丝瓜 | 91香焦视频 | 毛片网站网址 | 国产成人精品自拍视频 | 精品一区二区在线观看视频 | 精品一区二区三区在线观看视频 | lutube成人福利在线观看 | 亚洲午夜在线 | 性欧美日本 | 欧美国产免费 | 日本a∨精品中文字幕在线 狠狠干精品视频 | 久久经典免费视频 | 国产精品久久久久久久久久尿 | 亚洲日色| 91在线视频在线观看 | 久草在线播放视频 | 欧美激情视频一区二区免费 | 羞羞的网址 | 欧美精品一区二区久久久 | 久久蜜桃精品一区二区三区综合网 | 午夜激情视频免费 | 福利免费在线 | 国产精品久久久久久久午夜片 | 国产成人精品视频在线 | 性看小视频 | 巨乳激情| 日本在线视频一区二区三区 | 被啪羞羞视频在线观看 | 国产成人高清成人av片在线看 | 日韩精品一二三 | 免费毛片免费看 | 成人一区久久 | 孕妇体内谢精满日本电影 | 激情宗合 | 看中国一级毛片 |