GeorgiLukanov87

02. Programming Fundamentals Final Exam 300/300

Jul 14th, 2022 (edited)
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.15 KB | None | 0 0
  1. # 02. Programming Fundamentals Final Exam 300/300
  2. # https://judge.softuni.org/Contests/Practice/Index/2518#0
  3. #
  4. # 01. World Tour
  5. # 02. Destination Mapper
  6. # 03. Plant Discovery
  7.  
  8. \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  9.  
  10. # 01. World Tour
  11.  
  12. def is_index_valid(some_index: int):
  13.     if 0 <= some_index < len(data):
  14.         return True
  15.     return False
  16.  
  17.  
  18. data = input()
  19. command = input()
  20.  
  21. while not command == 'Travel':
  22.     command = command.split(":")
  23.     if command[0] == 'Add Stop':
  24.         index = int(command[1])
  25.         string = command[2]
  26.         if is_index_valid(index):
  27.             data = data[:index] + string + data[index:]
  28.  
  29.     elif command[0] == 'Remove Stop':
  30.         start_index = int(command[1])
  31.         end_index = int(command[2])
  32.         if is_index_valid(start_index) and is_index_valid(end_index):
  33.             data = data[:start_index] + data[end_index + 1:]
  34.  
  35.     elif command[0] == 'Switch':
  36.         old_str = command[1]
  37.         new_str = command[2]
  38.         if old_str in data:
  39.             data = data.replace(old_str, new_str)
  40.  
  41.     print(data)
  42.     command = input()
  43.  
  44. print(f"Ready for world tour! Planned stops: {data}")
  45.  
  46. \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  47.  
  48.  
  49. # 02. Destination Mapper
  50.  
  51. import re
  52.  
  53. data = input()
  54. pattern = r'(\=|\/)([A-Z][A-Za-z]{2,})\1'
  55.  
  56. valid_info = re.finditer(pattern, data)
  57. valid_cities = [match.group(2) for match in valid_info]
  58. travel_points = 0
  59. destinations = []
  60. for city_name in valid_cities:
  61.     travel_points += len(city_name)
  62.     destinations.append(city_name)
  63.  
  64. print(f'Destinations: {", ".join(destinations)}')
  65. print(f'Travel Points: {travel_points}')
  66.  
  67. \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  68.  
  69. # 03. Plant Discovery
  70.  
  71. n = int(input())
  72. data = {}
  73.  
  74. for _ in range(n):
  75.     command = input().split('<->')
  76.     plant = command[0]
  77.     rarity = int(command[1])
  78.     if plant not in data:
  79.         data[plant] = [rarity] + [0]
  80.     else:
  81.         data[plant][0] = rarity
  82. command = input()
  83. while not command == 'Exhibition':
  84.     command = command.split(": ")
  85.     details = command[1]
  86.     details = details.split(" - ")
  87.     name = details[0]
  88.     if name not in data:
  89.         print('error')
  90.         command = input()
  91.         continue
  92.     if command[0] == 'Rate':
  93.         rate = int(details[1])
  94.         if name in data:
  95.             if data[name][1] == 0:
  96.                 data[name][1] += rate
  97.             else:
  98.                 data[name][1] += rate
  99.                 data[name][1] /= 2
  100.  
  101.     elif command[0] == 'Update':
  102.         details = command[1]
  103.         details = details.split(' - ')
  104.         rate = int(details[1])
  105.         if name in data:
  106.             data[name][0] = rate
  107.     elif command[0] == 'Reset':
  108.         if name in data:
  109.             data[name][1] = 0
  110.     command = input()
  111. print("Plants for the exhibition:")
  112. for el in data:
  113.     print(f"- {el}; Rarity: {data[el][0]}; Rating: {data[el][1]:.2f}")
  114.  
  115. \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  116.  
  117.  
Add Comment
Please, Sign In to add comment