Advertisement
GeorgiLukanov87

anonymous_shitz_70/100

Jun 23rd, 2022
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. data = input().split(' ')
  2. command = input()
  3.  
  4. while not command == '3:1':
  5.     details = command.split(' ')
  6.     if details[0] == 'merge':
  7.         start_index = int(details[1])
  8.         end_index = int(details[2])
  9.         if start_index < 0:
  10.             start_index = 0
  11.         if end_index > (len(data) - 1):
  12.             end_index = len(data) - 1
  13.         merged_string = "".join(data[start_index:(end_index + 1)])
  14.         data[start_index:end_index + 1] = [merged_string]
  15.  
  16.     elif details[0] == 'divide':
  17.         divide = int(details[1])
  18.         parts = int(details[2])
  19.  
  20.         element = data[divide]
  21.         result = len(element) // parts
  22.         new_data = []
  23.  
  24.         while len(element) > 0:
  25.             new_data.append(element[:result])
  26.             removed = element.replace(element[:result], "")
  27.             element = removed
  28.  
  29.         while len(new_data) > parts:
  30.             poped = new_data.pop(-1)
  31.             new_data[-1] += poped
  32.         new_data = ' '.join(new_data)
  33.         data[divide] = new_data
  34.  
  35.     command = input()
  36.  
  37. print(*data)
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement