Advertisement
Guest User

Merge sequences

a guest
Nov 12th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. from sys import stdin
  2.  
  3.  
  4. def isSpace(ch):
  5.     return ch in " \n\f\r\t\v"
  6.  
  7.  
  8. def isNum(ch):
  9.     return ord(ch) >= ord('0') and ord(ch) <= ord('9') or ch == '-'
  10.  
  11.  
  12. # čte bílé znaky dokud nenarazí na jakýkoli jiný znak
  13. # poté čte dokud nenarazí na jakýkoli text
  14. def read():
  15.     out = ''
  16.     ch = stdin.read(1)
  17.     while isSpace(ch):
  18.         ch = stdin.read(1)
  19.     while isNum(ch):
  20.         out += ch
  21.         ch = stdin.read(1)
  22.     return out
  23.  
  24.  
  25. # použije funkci read a appenduje do listu
  26. def readList(inp):
  27.     ret = []
  28.     for i in range(inp):
  29.         ret.append(int(read()))
  30.     return ret
  31.  
  32.  
  33. # nejdříve přečte list o N číslech
  34. inp = readList(int(read()))
  35.  
  36. # postupně porovnává přečtený prvek druhého listu o M číslech
  37. j = 0
  38. for i in range(int(read())):
  39.     temp = int(read())
  40.     while j < len(inp) and temp >= inp[j]:
  41.         print(inp[j], end=' ')
  42.         j += 1
  43.     print(temp, end=' ')
  44.  
  45. # vytiskne zbytek pole
  46. for i in range(j, len(inp)):
  47.     print(inp[i], end=' ')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement