Advertisement
Nenogzar

9_anonymous_threat

Feb 10th, 2024
1,202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.22 KB | None | 0 0
  1. main_string = input().split()
  2. commands = input()
  3.  
  4. while commands != "3:1":
  5.     command, start_index, end_index = [int(x) if x[-1].isdigit() else x for x in commands.split()]
  6.  
  7.     if command == "merge":
  8.         if start_index < 0:
  9.             start_index = 0
  10.         if start_index < end_index:
  11.             how_long = len(main_string)
  12.             if end_index >= how_long:
  13.                 end_index = how_long - 1
  14.             for num in range(start_index, end_index):
  15.                 main_string[start_index] += f"{main_string.pop(start_index + 1)}"
  16.  
  17.     elif command == "divide":
  18.         index_ = start_index
  19.         partitions = end_index
  20.         if 0 <= index_ < len(main_string):
  21.             how_long = len(main_string[index_])
  22.             space_between = how_long // partitions
  23.             string_to_change = main_string.pop(index_)
  24.             result_ = []
  25.             for x in range(partitions - 1):
  26.                 result_.append(string_to_change[:space_between])
  27.                 string_to_change = string_to_change[space_between:]
  28.             result_.append(string_to_change)
  29.             for x in result_[::-1]:
  30.                 main_string.insert(index_, x)
  31.  
  32.     commands = input()
  33.  
  34. print(" ".join(main_string))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement