Nikolay9

16.anonymous_threat

Feb 21st, 2023
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | None | 0 0
  1. words = input().split()
  2.  
  3. while True:
  4.     command_list = input().split()
  5.     task = command_list[0]
  6.     if task == "3:1":
  7.         break
  8.  
  9.     elif task == "merge":
  10.         try:
  11.             for idx in range(int(command_list[2]) - int(command_list[1])):
  12.                 words[int(command_list[1])] += words[int(command_list[1]) + 1]
  13.                 words.pop(int(command_list[1]) + 1)
  14.         except IndexError:
  15.             pass
  16.  
  17.     elif task == "divide":
  18.         word = int(command_list[1])
  19.         idx = words.index(words[word]) + 1
  20.         partitions = int(command_list[2])
  21.         length_partition = len(words[word]) // partitions
  22.  
  23.         for _ in range(partitions):
  24.             if len(words[word]) < partitions:
  25.                 words.insert(idx, words[word])
  26.                 words.pop(word)
  27.                 break
  28.             words.insert(idx, words[word][:length_partition])
  29.             words[word] = words[word][length_partition:]
  30.             idx += 1
  31.  
  32.         for word in words:
  33.             if len(word) == 0:
  34.                 words.remove(word)
  35.  
  36. print(" ".join(words))
  37.  
Advertisement
Add Comment
Please, Sign In to add comment