Advertisement
usmiwka80

9.Anonymous Threat

Jan 19th, 2025 (edited)
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.46 KB | Software | 0 0
  1. single_line = input().split()
  2. list_data = [num for num in single_line]
  3. command_info = input()
  4. list_index = list()
  5. elements_to_move = list()
  6. new_substrings = list()
  7. while command_info != "3:1":
  8.     command = command_info.split()[0]
  9.     if command == "merge":
  10.         start_Index = command_info.split()[1]
  11.         start_Index = int(start_Index)
  12.         end_Index = command_info.split()[2]
  13.         end_Index = int(end_Index)
  14.         if len(list_data) < start_Index and len(list_data) < end_Index:
  15.             command_info = input()
  16.             continue
  17.         elif start_Index < 0:
  18.             start_Index == 0
  19.         elif end_Index >= len(list_data) > start_Index:
  20.             end_Index = len(list_data) - 1
  21.         # Extract elements by index
  22.         for i in range(start_Index, end_Index + 1):
  23.             list_index.append(i)
  24.             elements_to_move = [list_data[i] for i in sorted(list_index, reverse=True)]
  25.         elements_to_move.reverse()
  26.         result = ''.join(str(item) for item in elements_to_move)
  27.         elements_to_move.clear()
  28.         # remove elements from list_data
  29.         for i in sorted(list_index, reverse=True):
  30.             del list_data[i]
  31.         list_index.clear()
  32.         # Insert the extracted elements to list_data
  33.         list_data.insert(start_Index, result)
  34.     elif command == "divide":
  35.         index_data = command_info.split()[1]
  36.         index_data = int(index_data)
  37.         partition = command_info.split()[2]
  38.         partition = int(partition)
  39.         text = list_data[index_data]
  40.         list_data.pop(index_data)
  41.         # Determine the length of each substring
  42.         chunk_size = len(text)//partition
  43.         # Divide the string into 'partition' number of substrings
  44.         substrings = [text[i:i + chunk_size] for i in range(0, len(text), chunk_size)]
  45.         # If there are any leftover characters, add them to the last substring
  46.         new_substrings = ' '.join(substrings)
  47.         if len(substrings) > partition:
  48.             new_substrings = substrings[: partition - 1]
  49.             del substrings[: partition -1]
  50.             result_list = [''.join(str(item) for item in substrings)]
  51.             new_substrings += result_list
  52.             result_list.clear()
  53.             new_substrings = ' '.join(new_substrings)
  54.         list_data.insert(index_data, new_substrings)
  55.         new_substrings = list()
  56.         substrings.clear()
  57.     command_info = input()
  58. joined_string = ' '.join(list_data)
  59. print(joined_string)
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement