Advertisement
GeorgiLukanov87

03. Treasure Finder Text Processing - More Exercises 100/100

Jul 22nd, 2022 (edited)
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | None | 0 0
  1. # 03. Treasure Finder Text Processing - More Exercises 100/100
  2. # https://judge.softuni.org/Contests/Practice/Index/1741#0
  3.  
  4.  
  5. def find_treasure(some_str: str):
  6.     some_str = some_str.split('&')
  7.     treasure_found = some_str[1]
  8.     return treasure_found
  9.  
  10.  
  11. def find_location(some_str):
  12.     start_index = some_str.index('<')
  13.     end_index = some_str.index('>')
  14.     location_found = some_str[start_index+1:end_index]
  15.     return location_found
  16.  
  17.  
  18. keys = list(map(int, input().split(" ")))
  19. command = input()
  20.  
  21. while not command == 'find':
  22.     new_string = ""
  23.     string = command
  24.     index_counter = 0
  25.     key_counter = 0
  26.     len_of_string = len(string)
  27.     while True:
  28.         len_of_string -= 1
  29.         if len_of_string < 0:
  30.             break
  31.         new_string += chr((ord(string[index_counter]) - keys[key_counter]))
  32.         index_counter += 1
  33.         key_counter += 1
  34.         if index_counter % len(keys) == 0:
  35.             index_counter = len(new_string)
  36.             key_counter = 0
  37.  
  38.     treasure = find_treasure(new_string)
  39.     location = find_location(new_string)
  40.     print(f'Found {treasure} at {location}')
  41.  
  42.     command = input()
  43.  
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement