Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 02. Programming Fundamentals Final Exam 300/300
- # https://judge.softuni.org/Contests/Practice/Index/2518#0
- #
- # 01. World Tour
- # 02. Destination Mapper
- # 03. Plant Discovery
- \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
- # 01. World Tour
- def is_index_valid(some_index: int):
- if 0 <= some_index < len(data):
- return True
- return False
- data = input()
- command = input()
- while not command == 'Travel':
- command = command.split(":")
- if command[0] == 'Add Stop':
- index = int(command[1])
- string = command[2]
- if is_index_valid(index):
- data = data[:index] + string + data[index:]
- elif command[0] == 'Remove Stop':
- start_index = int(command[1])
- end_index = int(command[2])
- if is_index_valid(start_index) and is_index_valid(end_index):
- data = data[:start_index] + data[end_index + 1:]
- elif command[0] == 'Switch':
- old_str = command[1]
- new_str = command[2]
- if old_str in data:
- data = data.replace(old_str, new_str)
- print(data)
- command = input()
- print(f"Ready for world tour! Planned stops: {data}")
- \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
- # 02. Destination Mapper
- import re
- data = input()
- pattern = r'(\=|\/)([A-Z][A-Za-z]{2,})\1'
- valid_info = re.finditer(pattern, data)
- valid_cities = [match.group(2) for match in valid_info]
- travel_points = 0
- destinations = []
- for city_name in valid_cities:
- travel_points += len(city_name)
- destinations.append(city_name)
- print(f'Destinations: {", ".join(destinations)}')
- print(f'Travel Points: {travel_points}')
- \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
- # 03. Plant Discovery
- n = int(input())
- data = {}
- for _ in range(n):
- command = input().split('<->')
- plant = command[0]
- rarity = int(command[1])
- if plant not in data:
- data[plant] = [rarity] + [0]
- else:
- data[plant][0] = rarity
- command = input()
- while not command == 'Exhibition':
- command = command.split(": ")
- details = command[1]
- details = details.split(" - ")
- name = details[0]
- if name not in data:
- print('error')
- command = input()
- continue
- if command[0] == 'Rate':
- rate = int(details[1])
- if name in data:
- if data[name][1] == 0:
- data[name][1] += rate
- else:
- data[name][1] += rate
- data[name][1] /= 2
- elif command[0] == 'Update':
- details = command[1]
- details = details.split(' - ')
- rate = int(details[1])
- if name in data:
- data[name][0] = rate
- elif command[0] == 'Reset':
- if name in data:
- data[name][1] = 0
- command = input()
- print("Plants for the exhibition:")
- for el in data:
- print(f"- {el}; Rarity: {data[el][0]}; Rating: {data[el][1]:.2f}")
- \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Add Comment
Please, Sign In to add comment