Advertisement
GeorgiLukanov87

01. Programming Fundamentals Final Exam Retake 300/300

Jul 14th, 2022
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.32 KB | None | 0 0
  1. # 01. Programming Fundamentals Final Exam Retake 300/300
  2. # https://judge.softuni.org/Contests/Practice/Index/2525#0
  3. #
  4. # 01. The Imitation Game
  5. # 02. Ad Astra
  6. # 03. The Pianist
  7.  
  8. ???????????????????????????????????????????????????????????????????????????????????????????????
  9.  
  10. # 01. The Imitation Game
  11.  
  12. message = input()
  13. command = input()
  14.  
  15. while not command == "Decode":
  16.     command = command.split("|")
  17.     if command[0] == "ChangeAll":
  18.         substring = command[1]
  19.         replace = command[2]
  20.         message = message.replace(substring,replace)
  21.  
  22.     elif command[0] == "Insert":
  23.         index = int(command[1])
  24.         value = command[2]
  25.         message = message[:index] + value + message[index:]
  26.  
  27.     elif command[0] == 'Move':
  28.         num = int(command[1])
  29.         message = message[num:] + message[:num]
  30.  
  31.     command = input()
  32.  
  33. print(f"The decrypted message is: {message}")
  34.  
  35. ???????????????????????????????????????????????????????????????????????????????????????????????
  36.  
  37. # 02. Ad Astra
  38.  
  39. import re
  40.  
  41. data = input()
  42. pattern = r'(?P<sep1>(\#|\|))(?P<Food>[A-Za-z\s]+)(?P=sep1)' \
  43.           r'(?P<Date>\d{2}/\d{2}/\d{2})(?P=sep1)(?P<Calories>\d{1,5})(?P=sep1)'
  44.  
  45. my_products_details = []
  46. total_calories = []
  47.  
  48. valid_input = re.finditer(pattern, data)
  49. for el in valid_input:
  50.     current_el = el.groupdict()
  51.     total_calories.append(int(current_el['Calories']))
  52.     print_string = f"Item: {current_el['Food']}, Best before: {current_el['Date']}, Nutrition: {current_el['Calories']}"
  53.     my_products_details.append(print_string)
  54.  
  55. total_calories = sum(total_calories)
  56. food_per_day = total_calories // 2000
  57.  
  58. if food_per_day >= 1:
  59.     print(f'You have food to last you for: {food_per_day} days!')
  60.     for el in my_products_details:
  61.         print(el)
  62. else:
  63.     print(f'You have food to last you for: 0 days!')
  64.  
  65. ???????????????????????????????????????????????????????????????????????????????????????????????
  66.  
  67. # 03. The Pianist
  68.  
  69. n = int(input())
  70. data = {}
  71. for _ in range(n):
  72.     add_piece, add_composer, add_key = input().split("|")
  73.     data[add_piece] = [add_composer] + [add_key]
  74. command = input()
  75. while not command == 'Stop':
  76.     command = command.split("|")
  77.     if command[0] == 'Add':
  78.         piece = command[1]
  79.         composer = command[2]
  80.         key = command[3]
  81.         if piece in data:
  82.             print(f"{piece} is already in the collection!")
  83.         else:
  84.             data[piece] = [composer] + [key]
  85.             print(f"{piece} by {composer} in {key} added to the collection!")
  86.  
  87.     elif command[0] == 'Remove':
  88.         piece = command[1]
  89.         if piece not in data:
  90.             print(f"Invalid operation! {piece} does not exist in the collection.")
  91.         else:
  92.             print(f"Successfully removed {piece}!")
  93.             del data[piece]
  94.  
  95.     elif command[0] == 'ChangeKey':
  96.         piece = command[1]
  97.         new_key = command[2]
  98.         if piece not in data:
  99.             print(f"Invalid operation! {piece} does not exist in the collection.")
  100.         else:
  101.             data[piece][1] = new_key
  102.             print(f"Changed the key of {piece} to {new_key}!")
  103.  
  104.     command = input()
  105. for piece, value in data.items():
  106.     print(f"{piece} -> Composer: {value[0]}, Key: {value[1]}")
  107.  
  108. ???????????????????????????????????????????????????????????????????????????????????????????????
  109.  
  110.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement