GeorgiLukanov87

03. Programming Fundamentals Final Exam Retake 300/300

Jul 14th, 2022 (edited)
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.45 KB | None | 0 0
  1. # 03. Programming Fundamentals Final Exam Retake 300/300
  2. #https://judge.softuni.org/Contests/Practice/Index/2307#2
  3. #
  4. # 01. Secret Chat
  5. # 02. Mirror Words
  6. # 03. Need for Speed III
  7.  
  8. /////////////////////////////////////////////////////////////////////////////////////////////////////
  9.  
  10. # 01. Secret Chat
  11.  
  12. message = input()
  13. command = input()
  14.  
  15. while not command == 'Reveal':
  16.     command = command.split(":|:")
  17.     if command[0] == 'ChangeAll':
  18.         substring = command[1]
  19.         replacement = command[2]
  20.         message = message.replace(substring, replacement)
  21.  
  22.     elif command[0] == 'Reverse':
  23.         substring = command[1]
  24.         if substring in message:
  25.             message = message.replace(substring, "",1)
  26.             message = message + substring[::-1]
  27.         else:
  28.             print("error")
  29.             command = input()
  30.             continue
  31.  
  32.     elif command[0] == 'InsertSpace':
  33.         index = int(command[1])
  34.         message = message[:index] + " " + message[index:]
  35.  
  36.     print(message)
  37.  
  38.     command = input()
  39.  
  40. print(f"You have a new text message: {message}")
  41.  
  42. /////////////////////////////////////////////////////////////////////////////////////////////////////
  43.  
  44. # 02. Mirror Words
  45.  
  46. import re
  47.  
  48. string_data = input()
  49.  
  50. pattern = r'(\@|\#)([A-Za-z]{3,})\1(\@|\#)([A-Za-z]{3,})\3'
  51.  
  52. hidden_pairs = re.finditer(pattern, string_data)
  53. pairs_found = 0
  54. valid_pairs = []
  55.  
  56. for pair in hidden_pairs:
  57.     pairs_found += 1
  58.     word1 = pair.group(2)
  59.     word2 = pair.group(4)
  60.     if word1 == word2[::-1]:
  61.         valid_pairs.append(f'{word1} <=> {word2}')
  62.  
  63. if pairs_found > 0:
  64.     print(f"{pairs_found} word pairs found!")
  65. else:
  66.     print('No word pairs found!')
  67.  
  68. if valid_pairs:
  69.     print(f'The mirror words are:')
  70.     print(f'{", ".join(valid_pairs)}')
  71. else:
  72.     print('No mirror words!')
  73.  
  74. # 03. Need for Speed III
  75.  
  76. n_cars = int(input())
  77. data = {}
  78. command = input()
  79. for _ in range(n_cars):
  80.     car, mileage, fuel = command.split("|")
  81.     data[car] = [int(mileage)] + [int(fuel)]
  82.     command = input()
  83. while not command == 'Stop':
  84.     command = command.split(' : ')
  85.     if command[0] == 'Drive':
  86.         car = command[1]
  87.         distance = int(command[2])
  88.         fuel = int(command[3])
  89.         if data[car][1] >= fuel:
  90.             print(f"{car} driven for {distance} kilometers. {fuel} liters of fuel consumed.")
  91.             data[car][0] += distance
  92.             data[car][1] -= fuel
  93.         else:
  94.             print(f"Not enough fuel to make that ride")
  95.         if data[car][0] >= 100000:
  96.             print(f"Time to sell the {car}!")
  97.             del data[car]
  98.     elif command[0] == 'Refuel':
  99.         car = command[1]
  100.         fuel = int(command[2])
  101.         temp_tank = data[car][1]
  102.         if temp_tank + fuel >= 75:
  103.             print(f"{car} refueled with {75-temp_tank} liters")
  104.             data[car][1] = 75
  105.         else:
  106.             print(f"{car} refueled with {fuel} liters")
  107.             data[car][1] += fuel
  108.     elif command[0] == 'Revert':
  109.         car = command[1]
  110.         kilometers = int(command[2])
  111.         print(f"{car} mileage decreased by {kilometers} kilometers")
  112.         data[car][0] -= kilometers
  113.         if data[car][0] < 10000:
  114.             data[car][0] = 10000
  115.     command = input()
  116. for car in data:
  117.     print(f"{car} -> Mileage: {data[car][0]} kms, Fuel in the tank: {data[car][1]} lt.")
  118.  
  119. /////////////////////////////////////////////////////////////////////////////////////////////////////
  120.  
Add Comment
Please, Sign In to add comment