"Title description"
Enter an array of positive integers, combine all the numbers in the array into a number, and print the smallest of all the numbers that can be stitched together.
For example, the input array {3,32,321} prints out the smallest number 321323 that these three numbers can rank.
"The Test Center"
1. It is difficult to come up with new comparison rules to sort an array;
2. It is difficult to prove the array after sorting according to this rule, and connect the numbers in the immediate minimum number;
3. To solve the problem of large numbers, the sum of int may overflow, can be solved by string comparison;
"Solutions"
My code implementation is for reference only:
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Collections;6 7 namespaceConsoleApplication18 {9 class ProgramTen { One Static voidMain (string[] args) A { - int[] arr =New int[] {2,1 }; - Printminnumber (arr); the } - - Public Static voidPrintminnumber (int[] arr) - { + if(arr = =NULL|| Arr. Length <1) - return; + A string[] STRs =New string[arr. Length]; at - for(inti =0; I < arr. Length; i++) - { -Strs[i] =Arr[i]. ToString (); - } - inArray.Sort (STRs,NewMycompare ()); - to foreach(stringStrinchSTRs) + { - Console.Write (str); the } * } $ }Panax Notoginseng - Public classMycompare:icomparer the { + Public intCompare (ObjectObja,ObjectOBJB) A { the stringStra = (string) Obja; + stringStrB = (string) OBJB; - $ stringBegina = Strb.insert (0, stra); $ stringBEGINB = Stra.insert (0, StrB); - - returnBegina.compareto (BEGINB); the } - }Wuyi}
"Face question 33" rows the array into the smallest number