th0m45s5helby

Untitled

Jun 8th, 2021
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1.  
  2. def nextGreat(numlist,N):
  3.  
  4.     for i in range(N-1,0,-1):
  5.         if numlist[i] > numlist[i-1]:
  6.             break
  7.  
  8.     answer = numlist[i-1]
  9.     small = i
  10.     for j in range(i+1,N):
  11.         if numlist[j] > answer and numlist[j] < numlist[small]:
  12.             small = j
  13.    
  14.        
  15.     numlist[small],numlist[i-1] = numlist[i-1], numlist[small]
  16.    
  17.  
  18.     answer=int(str(''.join(map(str,numlist)))[:i])
  19.    
  20.     numlist = sorted(numlist[i:])
  21.    
  22.     for j in range(N-i):
  23.         answer = answer * 10 + int(numlist[j])
  24.    
  25.    
  26.     print(answer)
  27.  
  28. input1=3
  29. input2="182"
  30.  
  31. numlist = list(input2)
  32. nextGreat(numlist, input1)
  33.  
  34.  
Advertisement
Add Comment
Please, Sign In to add comment