Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 01. Programming Fundamentals Final Exam Retake With FUNCTIONS ! 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
- def change_all_func(message, substring, replacement):
- if substring in message:
- message = message.replace(substring, replacement)
- return message
- def insert_func(message, index, value):
- message = message[:index] + value + message[index:]
- return message
- def move_func(message, num_of_letters):
- message = message[num_of_letters:] + message[:num_of_letters]
- return message
- message = input()
- command = input()
- while not command == 'Decode':
- details = command.split('|')
- if details[0] == 'ChangeAll':
- substring = details[1]
- replacement = details[2]
- message = change_all_func(message, substring, replacement)
- elif details[0] == 'Insert':
- index = int(details[1])
- value = details[2]
- message = insert_func(message, index, value)
- elif details[0] == 'Move':
- num_of_letters = int(details[1])
- message = move_func(message, num_of_letters)
- command = input()
- print(f'The decrypted message is: {message}')
- =======================================================================================================
- # 02. Ad Astra
- def extract_datas(some_matches):
- my_data_list = []
- calories_sum = []
- for information in some_matches:
- string_to_print = f"Item: {information[1]}, Best before: {information[2]}, Nutrition: {information[3]}"
- my_data_list.append(string_to_print)
- calories_sum.append(int(information[3]))
- return my_data_list, sum(calories_sum) // 2000
- def final_print(some_data, some_days):
- print(f'You have food to last you for: {some_days} days!')
- if some_data:
- for datas in some_data:
- print(datas)
- import re
- data = input()
- pattern = r'(\#|\|)([A-Za-z\s*]+)\1(\d{2}\/\d{2}\/\d{2})\1(\d{1,5})\1'
- matched = re.findall(pattern, data)
- extracted_datas, days = extract_datas(matched)
- final_print(extracted_datas, days)
- =======================================================================================================
- # 03. The Pianist
- def add_func(some_datas):
- piece = some_datas[1]
- composer = some_datas[2]
- key = some_datas[3]
- if piece not in collection.keys():
- collection[piece] = {'composer': composer, 'key': key}
- print(f"{piece} by {composer} in {key} added to the collection!")
- else:
- print(f'{piece} is already in the collection!')
- def remove_func(some_datas):
- piece = some_datas[1]
- if piece in collection.keys():
- del collection[piece]
- print(f"Successfully removed {piece}!")
- else:
- print(f"Invalid operation! {piece} does not exist in the collection.")
- def change_key_func(some_datas):
- piece = some_datas[1]
- new_key = some_datas[2]
- if piece in collection.keys():
- collection[piece]["key"] = new_key
- print(f"Changed the key of {piece} to {new_key}!")
- else:
- print(f"Invalid operation! {piece} does not exist in the collection.")
- n = int(input())
- collection = {}
- for _ in range(n):
- data = input().split("|")
- piece = data[0]
- composer = data[1]
- key = data[2]
- if composer not in collection:
- collection[piece] = {}
- collection[piece] = {'composer': composer, 'key': key}
- else:
- collection[piece].update({'composer': composer, 'key': key})
- command = input()
- while not command == 'Stop':
- details = command.split('|')
- if details[0] == 'Add':
- add_func(details)
- elif details[0] == 'Remove':
- remove_func(details)
- elif details[0] == 'ChangeKey':
- change_key_func(details)
- command = input()
- for key, value in collection.items():
- print(f'{key} -> Composer: {value["composer"]}, Key: {value["key"]}')
- =======================================================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement