The sword offer-the array into the smallest number.
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.
Exercises
Use the CMP function of the sort function to arrange the smallest to largest number of combinations
BOOL Cmp (int a, int b) { int a_num = 0, B_num = 0, at = a, bt = b; while (at) { a_num++; at/=; } while (BT) { b_num++; BT/=; } at = B*pow (ten, a_num) + A; BT = A*pow (Ten, b_num) + B; Return BT < at; }class Solution {public: string printminnumber (vector<int> numbers) { sort (numbers.begin (), Numbers.end (), Cmp); String ans = ""; for (int i=0; i<numbers.size (); ++i) { ans + to_string (numbers[i]); } return ans; };
The sword offer-the array into the smallest number.