0% found this document useful (0 votes)
40 views4 pages

Need For Speed III - Problem Description

The document provides examples and instructions for a programming problem that simulates driving and maintaining a collection of cars. You receive information on cars with their mileage and fuel, then commands to drive cars, refuel them, and adjust their mileage until receiving a "Stop" command, after which you output the status of each car.

Uploaded by

martbul01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views4 pages

Need For Speed III - Problem Description

The document provides examples and instructions for a programming problem that simulates driving and maintaining a collection of cars. You receive information on cars with their mileage and fuel, then commands to drive cars, refuel them, and adjust their mileage until receiving a "Stop" command, after which you output the status of each car.

Uploaded by

martbul01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Problem 3 - Need for Speed III

Problem for exam preparation for the Programming Fundamentals Course @SoftUni.
Submit your solutions in the SoftUni judge system at https://judge.softuni.org/Contests/Practice/Index/2307#2.

You have just bought the latest and greatest computer game – Need for Seed III. Pick your favorite cars and drive
them all you want! We know that you can't wait to start playing.
On the first line of the standard input, you will receive an integer n – the number of cars that you can obtain. On the
next n lines, the cars themselves will follow with their mileage and fuel available, separated by "|" in the following
format:
"{car}|{mileage}|{fuel}"
Then, you will be receiving different commands, each on a new line, separated by " : ", until the "Stop"
command is given:
 "Drive : {car} : {distance} : {fuel}":
o You need to drive the given distance, and you will need the given fuel to do that. If the car doesn't
have enough fuel, print: "Not enough fuel to make that ride"
o If the car has the required fuel available in the tank, increase its mileage with the given distance,
decrease its fuel with the given fuel, and print:
"{car} driven for {distance} kilometers. {fuel} liters of fuel consumed."
o You like driving new cars only, so if a car's mileage reaches 100 000 km, remove it from the
collection(s) and print: "Time to sell the {car}!"
 "Refuel : {car} : {fuel}":
o Refill the tank of your car.
o Each tank can hold a maximum of 75 liters of fuel, so if the given amount of fuel is more than you
can fit in the tank, take only what is required to fill it up.
o Print a message in the following format: "{car} refueled with {fuel} liters"
 "Revert : {car} : {kilometers}":
o Decrease the mileage of the given car with the given kilometers and print the kilometers you have
decreased it with in the following format:
"{car} mileage decreased by {amount reverted} kilometers"
o If the mileage becomes less than 10 000km after it is decreased, just set it to 10 000km and
DO NOT print anything.
Upon receiving the "Stop" command, you need to print all cars in your possession in the following format:
"{car} -> Mileage: {mileage} kms, Fuel in the tank: {fuel} lt."

Input/Constraints
 The mileage and fuel of the cars will be valid, 32-bit integers, and will never be negative.
 The fuel and distance amounts in the commands will never be negative.
 The car names in the commands will always be valid cars in your possession.

Output
 All the output messages with the appropriate formats are described in the problem description.

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 1 of 4


Examples
Input Output

3 Audi A6 driven for 543 kilometers. 47

Audi A6|38000|62 liters of fuel consumed.

Mercedes CLS|11000|35 Mercedes CLS driven for 94


kilometers. 11 liters of fuel
Volkswagen Passat CC|45678|5
consumed.
Drive : Audi A6 : 543 : 47
Not enough fuel to make that ride
Drive : Mercedes CLS : 94 : 11
Audi A6 refueled with 50 liters
Drive : Volkswagen Passat CC : 69 : 8
Mercedes CLS mileage decreased by 500
Refuel : Audi A6 : 50
kilometers
Revert : Mercedes CLS : 500
Audi A6 -> Mileage: 10000 kms, Fuel
Revert : Audi A6 : 30000 in the tank: 65 lt.
Stop Mercedes CLS -> Mileage: 10594 kms,
Fuel in the tank: 24 lt.

Volkswagen Passat CC -> Mileage:


45678 kms, Fuel in the tank: 5 lt.

Comments

After we receive the cars with their mileage and fuel, we start driving them. When we get to "Drive : Volkswagen
Passat CC : 69 : 8" command, our program calculates that there is not enough fuel, and we print the appropriate
message. Then we refuel the Audi A6 with 50 l of fuel and Revert the Mercedes with 500 kilometers.
When we receive the "Revert : Audi A6 : 30000", we set its mileage to 10000 km, because if the current mileage of
the Audi is 38543 kms and if we subtract 30000 from it, we receive 8543 kms, which is less than 10000 kms.
After all the commands, we print our current collection of cars with their current mileage and current fuel.

Input Output

4 Not enough fuel to make that ride

Lamborghini Veneno|11111|74 Aston Martin Valkryie driven for 99

Bugatti Veyron|12345|67 kilometers. 23 liters of fuel


consumed.
Koenigsegg CCXR|67890|12
Aston Martin Valkryie driven for 2
Aston Martin Valkryie|99900|50
kilometers. 1 liters of fuel
Drive : Koenigsegg CCXR : 382 : 82
consumed.
Drive : Aston Martin Valkryie : 99 : 23
Time to sell the Aston Martin
Drive : Aston Martin Valkryie : 2 : 1 Valkryie!

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 2 of 4


Refuel : Lamborghini Veneno : 40 Lamborghini Veneno refueled with 1

Revert : Bugatti Veyron : 2000 liters

Stop Bugatti Veyron mileage decreased by


2000 kilometers

Lamborghini Veneno -> Mileage: 11111


kms, Fuel in the tank: 75 lt.

Bugatti Veyron -> Mileage: 10345 kms,


Fuel in the tank: 67 lt.

Koenigsegg CCXR -> Mileage: 67890


kms, Fuel in the tank: 12 lt.

JS Examples
Input Output

[ Audi A6 driven for 543 kilometers.

'3', 47 liters of fuel consumed.

'Audi A6|38000|62', Mercedes CLS driven for 94


kilometers. 11 liters of fuel
'Mercedes CLS|11000|35',
consumed.
'Volkswagen Passat CC|45678|5',
Not enough fuel to make that ride
'Drive : Audi A6 : 543 : 47',
Audi A6 refueled with 50 liters
'Drive : Mercedes CLS : 94 : 11',
Mercedes CLS mileage decreased by
'Drive : Volkswagen Passat CC : 69 : 8',
500 kilometers
'Refuel : Audi A6 : 50',
Audi A6 -> Mileage: 10000 kms, Fuel
'Revert : Mercedes CLS : 500', in the tank: 65 lt.
'Revert : Audi A6 : 30000', Mercedes CLS -> Mileage: 10594 kms,
'Stop' Fuel in the tank: 24 lt.

] Volkswagen Passat CC -> Mileage:


45678 kms, Fuel in the tank: 5 lt.

Comments

After we receive the cars with their mileage and fuel, we start driving them. When we get to "Drive : Volkswagen
Passat CC : 69 : 8" command, our program calculates that there is not enough fuel,0 and we print the appropriate
message. Then we refuel the Audi A6 with 50 l of fuel and Revert the Mercedes with 500 kilometers.
When we receive the "Revert : Audi A6 : 30000", we set its mileage to 10000 km, because if the current mileage of
the Audi is 38543 kms and if we subtract 30000 from it, we receive 8543 kms, which is less than 10000 kms.
After all the commands, we print our current collection of cars with their current mileage and current fuel.

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 3 of 4


Input Output

[ Not enough fuel to make that ride

'4', Aston Martin Valkryie driven for 99

'Lamborghini Veneno|11111|74', kilometers. 23 liters of fuel


consumed.
'Bugatti Veyron|12345|67',
Aston Martin Valkryie driven for 2
'Koenigsegg CCXR|67890|12',
kilometers. 1 liters of fuel
'Aston Martin Valkryie|99900|50',
consumed.
'Drive : Koenigsegg CCXR : 382 : 82',
Time to sell the Aston Martin
'Drive : Aston Martin Valkryie : 99 : 23', Valkryie!
'Drive : Aston Martin Valkryie : 2 : 1', Lamborghini Veneno refueled with 1
'Refuel : Lamborghini Veneno : 40', liters

'Revert : Bugatti Veyron : 2000', Bugatti Veyron mileage decreased by

'Stop' 2000 kilometers

] Lamborghini Veneno -> Mileage:


11111 kms, Fuel in the tank: 75 lt.

Bugatti Veyron -> Mileage: 10345


kms, Fuel in the tank: 67 lt.

Koenigsegg CCXR -> Mileage: 67890


kms, Fuel in the tank: 12 lt.

© SoftUni – https://softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.

Follow us: Page 4 of 4

You might also like