The title description enters an array of positive integers, stitching up all the numbers in the array into a number, and printing the smallest of all the numbers that can be stitched together. For example, enter the array {3,32,321}, then print out the minimum number that these three numbers can be ranked as 321323.
Given a collection of number segments, you is supposed to recover the smallest number from them. For example, given {321, 3214, 0229,}, 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 the one test case. Each case gives a positive an integer n (<=10000) followed by N number segments. Each segment contains a non-negative an integer of no more than 8 digits. All the numbers in a line is separated by a space.
Output Specification:
For each test case, print the smallest number on one line. Do not output leading zeros.
Sample Input:
5 32 321 3214 0229 87
Sample Output:
22932132143287
1 classSolution2 {3 Public: 4 stringPrintminnumber (vector<int>num)5 {6 stringAns ="";7 intLen =num.size ();8 if(len==0)9 returnans;Tenvector<string>nums (len); One for(inti =0; i<len; i++) ANums[i] =to_string (Num[i]); - sort (Nums.begin (), Nums.end (), CMP); - for(inti =0; i<len; i++) theans+=Nums[i]; - returnans; - } - Static intcmpConst string&S1,Const string&S2) + { - returns1+s2<s2+S1; + } A};
The array is ranked as the smallest number/1038. Recover the smallest number