SHARE
TWEET

Untitled

a guest Jun 25th, 2019 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. num1 = list(input())
  2. num2 = list(input())
  3.  
  4. #print(num1,num2)
  5. p1 = 0
  6. p2 = 0
  7.  
  8. result = []
  9.  
  10. while p1 < len(num1) and p2 < len(num2):
  11.     #print(p1, p2, result)
  12.     if num1[p1] < num2[p2]:
  13.         result.append(num1[p1])
  14.         p1 += 1
  15.     elif num2[p2] < num1[p1]:
  16.         result.append(num2[p2])
  17.         p2 += 1
  18.     else:
  19.         p1_ = p1
  20.         p2_ = p2
  21.        
  22.         while p1_ < len(num1) and p2_ < len(num2):
  23.             #print(p1,p2,p1_,p2_)
  24.             if num1[p1_] != num2[p2_] :
  25.                 break
  26.             p1_ += 1
  27.             p2_ += 1
  28.  
  29.         min1 = min(num1[p1:p1_+1])
  30.         min2 = min(num2[p2:p2_+1])
  31.        
  32.         if p1_ == len(num1):
  33.             min1 = min(num1[p1:])
  34.             min2 = min(num2[p2:])
  35.             p1_ = p1
  36.         if p2_ == len(num2):
  37.             min1 = min(num1[p1:])
  38.             min2 = min(num2[p2:])
  39.             p2_ = p2
  40.          
  41.        
  42.         if min1 > min2:
  43.             result.append(num2[p2])
  44.             p2 += 1
  45.         elif min1 < min2:
  46.             result.append(num1[p1])
  47.             p1 += 1
  48.         else:
  49.             if len(num1[p1:]) < len(num2[p2:]):
  50.                 result.append(num1[p1])
  51.                 p1 += 1
  52.             else:
  53.                 result.append(num2[p2])
  54.                 p2 += 1
  55.            
  56.  
  57. if p1 == len(num1):
  58.     result += num2[p2: ]
  59.  
  60. elif p2 == len(num2):
  61.     result += num1[p1: ]
  62.  
  63. print("".join(result))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top