Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- words = input().split()
- while True:
- command_list = input().split()
- task = command_list[0]
- if task == "3:1":
- break
- elif task == "merge":
- try:
- for idx in range(int(command_list[2]) - int(command_list[1])):
- words[int(command_list[1])] += words[int(command_list[1]) + 1]
- words.pop(int(command_list[1]) + 1)
- except IndexError:
- pass
- elif task == "divide":
- word = int(command_list[1])
- idx = words.index(words[word]) + 1
- partitions = int(command_list[2])
- length_partition = len(words[word]) // partitions
- for _ in range(partitions):
- if len(words[word]) < partitions:
- words.insert(idx, words[word])
- words.pop(word)
- break
- words.insert(idx, words[word][:length_partition])
- words[word] = words[word][length_partition:]
- idx += 1
- for word in words:
- if len(word) == 0:
- words.remove(word)
- print(" ".join(words))
Advertisement
Add Comment
Please, Sign In to add comment