November 2014-a given integer array is sorted by this integer group to minimize the value of each element in the sorted array.
My general idea is to convert this integer array into a string array, and then sort the array for the first time using the compareto method of the string class. The sorting result is exactly sorted by lexicographically, the Lexicographic Order exactly refers to the order of numbers from 0-9, which exactly meets this requirement. Finally, some may need to change the order to minimize the number.
Package com.cn. qunar. test;/*** @ author Liu Lijuan [email protected] * @ version Creation Time: 7:33:31 AM, January 1, August 2, 2014 Class description: given an integer array, sort the integer array, this minimizes the value of each element in the concatenated array in order. * Example: [3, 83, 8, 13, 1]. The sorted array is [1, 13, 3, 83, 8]. Splice them to obtain the minimum number of 1133838. */Public class intsort {public static void main (string [] ARGs) {int [] array = new int [] {3, 83, 8,101,101 03 }; string [] strings = new string [array. length]; for (INT I = 0; I <array. length; I ++) {strings [I] = integer. tostring (array [I]); system. out. println (strings [I]);} For (INT I = 0; I <strings. length-1; I ++) {for (Int J = 0; j <strings. length-I-1; j ++) {If (strings [J]. compareto (strings [J + 1])> 0) {system. out. println (strings [J] + ">" + strings [J + 1]); string temp = strings [J]; strings [J] = strings [J + 1]; strings [J + 1] = temp ;}}for (INT I = 0; I <strings. length; I ++) {system. out. println (strings [I]);} For (INT I = 0; I <strings. length-1; I ++) {int lengths = (strings [I]. length ()> strings [I + 1]. length ())? Strings [I + 1]. length (): strings [I]. length (); system. out. println ("Length:" + lengths); For (Int J = 0; j <lengths; j ++) {If (strings [I]. charat (j) = strings [I + 1]. charat (j) {int Si = integer. parseint (strings [I]); int Si1 = integer. parseint (strings [I + 1]); int SIM = 1; for (int K = 0; k <strings [I]. length (); k ++) {SIM * = 10;} int si1m = 1; for (int K = 0; k <strings [I + 1]. length (); k ++) {si1m * = 10;} If (SI * si1m + Si1)> (Si1 * Sim + Si) {system. out. println (SI * si1m + Si1) + ">" + (Si1 * Sim + Si); string temp = strings [I]; strings [I] = strings [I + 1]; strings [I + 1] = temp ;}}} stringbuffer sb = new stringbuffer (); For (INT I = 0; I <strings. length; I ++) {sb. append (strings [I]);} system. out. println ("sorting result:" + Sb );}}
Although the efficiency is not very high =, I think of it myself. The answer is incorrect. Http://zhidao.baidu.com/question/489460060.html