Question: enter a positive integer array, splice all the numbers in the array into a number, and print the smallest of all the numbers that can be spliced. For example, enter an array, {32,321 }, print the minimum number 32132 that can be arranged with the three numbers.
Sort the original integer array by comparing the size of the combined string. For example, 32 and 321 compare the result with "32321"> "32132", so 32 is considered to be greater than 321. Solve this problem by using the Bubble sorting method.
Int compare2int (int A, int B) {// compare the size of char S1 [10], S2 [10], tmp1 [10] of string a + B and string B + A; sprintf (S1, "% d", a); sprintf (tmp1, "% d", a); sprintf (S2, "% d", B); strcat (tmp1, s2); strcat (S2, S1); int result = strcmp (tmp1, S2); // compare the return result of AB and BA;} void bubblesort (int A [], int Len) {int TMP; For (INT I = 0; I <Len; I ++) {for (Int J = 1; j <len-I; j ++) {If (compare2int (A [J-1], a [J]) = 1) {// If a [J-1] a [J] is greater than a [J] a [J-1], it is considered that a [J-1] is greater than a [J] to exchange them TMP = A [J]; A [J] = A [J-1]; A [J-1] = TMP ;}}} for (int K = 0; k <Len; k ++) {printf ("% d", a [k]) ;}printf ("\ n ");} int main () {int test [] = {3, 32, 321}; bubblesort (test, 3); Return 0 ;}
Arrange the array into the smallest number