Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 01. Programming Fundamentals Final Exam Retake 300/300
- # https://judge.softuni.org/Contests/Practice/Index/2525#0
- #
- # 01. The Imitation Game
- # 02. Ad Astra
- # 03. The Pianist
- ???????????????????????????????????????????????????????????????????????????????????????????????
- # 01. The Imitation Game
- message = input()
- command = input()
- while not command == "Decode":
- command = command.split("|")
- if command[0] == "ChangeAll":
- substring = command[1]
- replace = command[2]
- message = message.replace(substring,replace)
- elif command[0] == "Insert":
- index = int(command[1])
- value = command[2]
- message = message[:index] + value + message[index:]
- elif command[0] == 'Move':
- num = int(command[1])
- message = message[num:] + message[:num]
- command = input()
- print(f"The decrypted message is: {message}")
- ???????????????????????????????????????????????????????????????????????????????????????????????
- # 02. Ad Astra
- import re
- data = input()
- pattern = r'(?P<sep1>(\#|\|))(?P<Food>[A-Za-z\s]+)(?P=sep1)' \
- r'(?P<Date>\d{2}/\d{2}/\d{2})(?P=sep1)(?P<Calories>\d{1,5})(?P=sep1)'
- my_products_details = []
- total_calories = []
- valid_input = re.finditer(pattern, data)
- for el in valid_input:
- current_el = el.groupdict()
- total_calories.append(int(current_el['Calories']))
- print_string = f"Item: {current_el['Food']}, Best before: {current_el['Date']}, Nutrition: {current_el['Calories']}"
- my_products_details.append(print_string)
- total_calories = sum(total_calories)
- food_per_day = total_calories // 2000
- if food_per_day >= 1:
- print(f'You have food to last you for: {food_per_day} days!')
- for el in my_products_details:
- print(el)
- else:
- print(f'You have food to last you for: 0 days!')
- ???????????????????????????????????????????????????????????????????????????????????????????????
- # 03. The Pianist
- n = int(input())
- data = {}
- for _ in range(n):
- add_piece, add_composer, add_key = input().split("|")
- data[add_piece] = [add_composer] + [add_key]
- command = input()
- while not command == 'Stop':
- command = command.split("|")
- if command[0] == 'Add':
- piece = command[1]
- composer = command[2]
- key = command[3]
- if piece in data:
- print(f"{piece} is already in the collection!")
- else:
- data[piece] = [composer] + [key]
- print(f"{piece} by {composer} in {key} added to the collection!")
- elif command[0] == 'Remove':
- piece = command[1]
- if piece not in data:
- print(f"Invalid operation! {piece} does not exist in the collection.")
- else:
- print(f"Successfully removed {piece}!")
- del data[piece]
- elif command[0] == 'ChangeKey':
- piece = command[1]
- new_key = command[2]
- if piece not in data:
- print(f"Invalid operation! {piece} does not exist in the collection.")
- else:
- data[piece][1] = new_key
- print(f"Changed the key of {piece} to {new_key}!")
- command = input()
- for piece, value in data.items():
- print(f"{piece} -> Composer: {value[0]}, Key: {value[1]}")
- ???????????????????????????????????????????????????????????????????????????????????????????????
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement