# 题目描述

1038 Recover the Smallest Number (30分)
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 (≤10^4) 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. Notice that the first digit must not be zero.

Sample Input:

5 32 321 3214 0229 87

Sample Output:

22932132143287

# 代码实现(AC)

#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
bool cmp(string a,string b)
{
return a+b<b+a;
}
void solve()
{
int n;
scanf("%d",&n);
string s[n];
for(int i=0;i<n;i++)
cin>>s[i];
sort(s,s+n,cmp);
string str;
for(int i=0;i<n;i++)
str+=s[i];
while(str[0]=='0')
{
str.erase(str.begin());
}
if(str.size())	cout<<str;
else cout<<"0";
}
int main()
{
solve();
return 0;
}


03-04 2222

08-27 120

08-19 65

01-29 24

11-07 147

08-02 112

02-16 42

12-30 1434

06-24 1333

08-21 582

08-10 53

08-31 69

02-24 85

01-18 51

08-15 55

02-26 950

02-28 99

08-11 11

01-25 194

03-19 83万+

#### 大学四年自学走来，这些私藏的实用工具/学习网站我贡献出来了

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客