DiYane

Anonymous threat

Sep 25th, 2023
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.34 KB | None | 0 0
  1. strings_input = input().split()
  2. result = []
  3. instructions = input()
  4. while not instructions == "3:1":
  5.     instructions = instructions.split()
  6.     command = instructions[0]
  7.     if command == 'merge':
  8.         start = int(instructions[1])
  9.         end = int(instructions[2])
  10.         if start < 0:
  11.             start = 0
  12.         if end > len(strings_input) - 1:
  13.             end = len(strings_input) - 1
  14.         for index, string in enumerate(strings_input):
  15.             if index in range(start + 1, end + 1):
  16.                 strings_input[start] += strings_input[index]
  17.         for index in range(end, start, - 1):
  18.             strings_input.pop(index)
  19.     elif command == 'divide':
  20.         index = int(instructions[1])
  21.         partitions = int(instructions[2])
  22.         if partitions > len(strings_input[index]):
  23.             step = 1
  24.         else:
  25.             step = len(strings_input[index]) // partitions
  26.         divide_part = strings_input.pop(index)
  27.         start = 0
  28.         for parts in range(partitions):
  29.             if parts == partitions - 1:
  30.                 strings_input.insert(index, divide_part[start::])
  31.                 break
  32.             else:
  33.                 strings_input.insert(index, divide_part[start: start + step:])
  34.             start += step
  35.             index += 1
  36.     instructions = input()
  37. print(' '.join(strings_input))
  38.  
Tags: python
Add Comment
Please, Sign In to add comment