Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 03. Programming Fundamentals Final Exam Retake 300/300
- #https://judge.softuni.org/Contests/Practice/Index/2307#2
- #
- # 01. Secret Chat
- # 02. Mirror Words
- # 03. Need for Speed III
- /////////////////////////////////////////////////////////////////////////////////////////////////////
- # 01. Secret Chat
- message = input()
- command = input()
- while not command == 'Reveal':
- command = command.split(":|:")
- if command[0] == 'ChangeAll':
- substring = command[1]
- replacement = command[2]
- message = message.replace(substring, replacement)
- elif command[0] == 'Reverse':
- substring = command[1]
- if substring in message:
- message = message.replace(substring, "",1)
- message = message + substring[::-1]
- else:
- print("error")
- command = input()
- continue
- elif command[0] == 'InsertSpace':
- index = int(command[1])
- message = message[:index] + " " + message[index:]
- print(message)
- command = input()
- print(f"You have a new text message: {message}")
- /////////////////////////////////////////////////////////////////////////////////////////////////////
- # 02. Mirror Words
- import re
- string_data = input()
- pattern = r'(\@|\#)([A-Za-z]{3,})\1(\@|\#)([A-Za-z]{3,})\3'
- hidden_pairs = re.finditer(pattern, string_data)
- pairs_found = 0
- valid_pairs = []
- for pair in hidden_pairs:
- pairs_found += 1
- word1 = pair.group(2)
- word2 = pair.group(4)
- if word1 == word2[::-1]:
- valid_pairs.append(f'{word1} <=> {word2}')
- if pairs_found > 0:
- print(f"{pairs_found} word pairs found!")
- else:
- print('No word pairs found!')
- if valid_pairs:
- print(f'The mirror words are:')
- print(f'{", ".join(valid_pairs)}')
- else:
- print('No mirror words!')
- # 03. Need for Speed III
- n_cars = int(input())
- data = {}
- command = input()
- for _ in range(n_cars):
- car, mileage, fuel = command.split("|")
- data[car] = [int(mileage)] + [int(fuel)]
- command = input()
- while not command == 'Stop':
- command = command.split(' : ')
- if command[0] == 'Drive':
- car = command[1]
- distance = int(command[2])
- fuel = int(command[3])
- if data[car][1] >= fuel:
- print(f"{car} driven for {distance} kilometers. {fuel} liters of fuel consumed.")
- data[car][0] += distance
- data[car][1] -= fuel
- else:
- print(f"Not enough fuel to make that ride")
- if data[car][0] >= 100000:
- print(f"Time to sell the {car}!")
- del data[car]
- elif command[0] == 'Refuel':
- car = command[1]
- fuel = int(command[2])
- temp_tank = data[car][1]
- if temp_tank + fuel >= 75:
- print(f"{car} refueled with {75-temp_tank} liters")
- data[car][1] = 75
- else:
- print(f"{car} refueled with {fuel} liters")
- data[car][1] += fuel
- elif command[0] == 'Revert':
- car = command[1]
- kilometers = int(command[2])
- print(f"{car} mileage decreased by {kilometers} kilometers")
- data[car][0] -= kilometers
- if data[car][0] < 10000:
- data[car][0] = 10000
- command = input()
- for car in data:
- print(f"{car} -> Mileage: {data[car][0]} kms, Fuel in the tank: {data[car][1]} lt.")
- /////////////////////////////////////////////////////////////////////////////////////////////////////
Add Comment
Please, Sign In to add comment