Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace NeedForSpeed
- {
- class Program
- {
- static void Main(string[] args)
- {
- int numberOfCars = int.Parse(Console.ReadLine());
- var dictCarMileageFuel = new Dictionary<string, List<int>>();
- for (int i = 0; i < numberOfCars; i++)
- {
- string[] input = Console.ReadLine().Split('|');
- string car = input[0];
- int mileage = int.Parse(input[1]);
- int fuel = int.Parse(input[2]);
- dictCarMileageFuel[car] = new List<int>();
- dictCarMileageFuel[car].Add(mileage);
- dictCarMileageFuel[car].Add(fuel);
- }
- string command = string.Empty;
- while ((command = Console.ReadLine()) != "Stop")
- {
- string[] commandArray = command.Split(" : ");
- if (commandArray[0] == "Drive")
- {
- string car = commandArray[1];
- int distance = int.Parse(commandArray[2]);
- int fuel = int.Parse(commandArray[3]);
- if(fuel> dictCarMileageFuel[car][1])
- {
- Console.WriteLine("Not enough fuel to make that ride");
- }
- else if (fuel <= dictCarMileageFuel[car][1])
- {
- dictCarMileageFuel[car][1] = dictCarMileageFuel[car][1] - fuel;
- dictCarMileageFuel[car][0] = dictCarMileageFuel[car][0] + distance;
- Console.WriteLine($"{car} driven for {distance} kilometers. {fuel} liters of fuel consumed.");
- if (dictCarMileageFuel[car][0]>=100000)
- {
- dictCarMileageFuel.Remove(car);
- Console.WriteLine($"Time to sell the {car}!");
- }
- }
- }
- else if (commandArray[0] == "Refuel")
- {
- string car = commandArray[1];
- int fuel =int.Parse( commandArray[2]);
- int initialFuel = dictCarMileageFuel[car][1];
- dictCarMileageFuel[car][1] = dictCarMileageFuel[car][1] + fuel;
- if (dictCarMileageFuel[car][1] > 75)
- {
- dictCarMileageFuel[car][1] = 75;
- int fuelAmount = 75 - initialFuel;
- Console.WriteLine($"{car} refueled with {fuelAmount} liters");
- }
- else if (dictCarMileageFuel[car][1] <= 75)
- {
- int fuelAmount = dictCarMileageFuel[car][1] - initialFuel;
- Console.WriteLine($"{car} refueled with {fuelAmount} liters");
- }
- }
- else if(commandArray[0] == "Revert")
- {
- string car = commandArray[1];
- int kilometers = int.Parse(commandArray[2]);
- int initialMileage = dictCarMileageFuel[car][0];
- dictCarMileageFuel[car][0] = dictCarMileageFuel[car][0] - kilometers;
- if (dictCarMileageFuel[car][0] < 10000)
- {
- dictCarMileageFuel[car][0] = 10000;
- }
- else
- {
- Console.WriteLine($"{car} mileage decreased by {kilometers} kilometers");
- }
- }
- }
- foreach (var kvp in dictCarMileageFuel.OrderByDescending(x=>x.Value[0]).ThenBy(x=>x.Key))
- {
- Console.WriteLine($"{kvp.Key} -> Mileage: {kvp.Value[0]} kms, Fuel in the tank: {kvp.Value[1]} lt.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement