2017/3/22
Today, Alibaba algorithm engineers online Pen test questions, time is tight, only 40 minutes, and not have time to tune out, when it is, this is later compiled through the code, posted here to facilitate reference learning. The
has n positive integers (less than 1 billion per number), representing them as strings. For each string s, can flip to the new string s ', such as "1234" can be flipped into "4321".
Now, connect the n strings in any order to a character token, and each string can choose whether or not to flip. In the word token, start at any point, traverse the entire loop, and get a long integer. Excuse me, how can I get the largest long integer.
arr = raw_input () arr_l = Arr.split (') N = Len (arr_l) print (n) for I in Range (n): str_l = L En (Arr_l[i]) if arr_l[i][0] < ARR_L[I][STR_L-1]: New = ' for index in range (str_l): Ne w = new+arr_l[i][str_l-1-index] arr_l[i] = New for i in Range (N): to J in range (I, N): If arr_l[i][ 0] < Arr_l[j][0]: temp = arr_l[i] arr_l[i] = arr_l[j] arr_l[j] = temp Elif Arr_l[i][0] = = Arr_l[j][0]: Len1 = Len (arr_l[i]) Len2 = Len (arr_l[j]) if Len1 < Len 2:l = Len1 Else:l = Len2 for k in range (1, L): I
F Arr_l[i][k] < Arr_l[j][k]: TEMP1 = arr_l[i] arr_l[i] = arr_l[j] ARR_L[J] = Temp1 break ans = ' to I in Range (N): print (arr_l[i]) Ans = Ans+arr_l[i] P Rint (Ans)
Input:
123 253 789
Output:
3
987
352
321
987352321