Problem Description:
Enter an array of positive integers, combine all the numbers in the array into a number, and print out the smallest of all the numbers that are stitched together. For example, the input array {3,32,321} prints out the smallest number 321323 that these 3 numbers can be taken.
C + + code:
voidPrintminnumber (int* Numbers,intLength) {if(numbers = = NULL | | length <=0)return;StringStreamss//used for numeric and string conversions; string* str=New string[Length]; for(inti =0; i < length; ++i) {ss.clear (); ss<<numbers[i]; ss>>str[i]; } sort (str,str+length, compare); for(inti =0; i < length; ++i)cout<< Str[i];printf("\ n");}BOOLCompareConst stringStrNumber1,Const stringStrNumber2) {stringSTR1 = Strnumber1+strnumber2;stringSTR2 = Strnumber2+strnumber1;returnSTR2>STR1;}
Solve with C + +: Arrange the array into the smallest number problem