Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Exam_Retake
- {
- class Program
- {
- static void Main(string[] args)
- {
- int numberOfCars = int.Parse(Console.ReadLine());
- Dictionary<string, int[]> cars = new Dictionary<string, int[]>();
- for (int i = 0; i < numberOfCars; i++)
- {
- string[] input = Console.ReadLine().Split("|").ToArray();
- int mileage = int.Parse(input[1]);
- int fuel = int.Parse(input[2]);
- cars.Add(input[0],new int[2]{mileage, fuel}); // cars --> Milleage | Fuel
- }
- string command = Console.ReadLine();
- while (command !="Stop")
- {
- if (command.Contains("Drive")) // Drive : {car} : {distance} : {fuel}
- {
- string[] splitCommand = command.Split(" : ");
- string currentCar = splitCommand[1];
- int currentMil = int.Parse(splitCommand[2]);
- int currentFuel = int.Parse(splitCommand[3]);
- int fuel = cars[currentCar][1];
- int mil = cars[currentCar][0];
- if (currentFuel <= fuel) // the car has enough fuel
- {
- cars[currentCar][0] += currentMil;
- cars[currentCar][1] -= currentFuel;
- Console.WriteLine($"{currentCar} driven for {currentMil} kilometers. {currentFuel} liters of fuel consumed.");
- }
- else if (currentFuel >= fuel) // not enough fuel
- {
- Console.WriteLine("Not enough fuel to make that ride");
- }
- else if (mil>=100000)
- {
- Console.WriteLine($"Time to sell the {currentCar}!");
- cars.Remove(currentCar);
- }
- }
- if (command.Contains("Refuel")) // Refuel : {car} : {fuel}
- {
- string[] splitCommand = command.Split(" : ");
- string currentCar = splitCommand[1];
- int currentFuel = int.Parse(splitCommand[2]);
- int fuel = cars[currentCar][1];
- if (fuel+currentFuel>75)
- {
- currentFuel = 75 - fuel;
- fuel = 75;
- }
- else
- {
- fuel += currentFuel;
- }
- Console.WriteLine($"{currentCar} refueled with {currentFuel} liters");
- }
- if (command.Contains("Revert")) // Revert : {car} : {kilometers}
- {
- string[] splitCommand = command.Split(" : ");
- string currentCar = splitCommand[1];
- int currentMil = int.Parse(splitCommand[2]);
- int mil = cars[currentCar][0];
- mil -= currentMil;
- if (mil<10000)
- {
- mil = 10000;
- }
- }
- command = Console.ReadLine();
- }
- cars = cars
- .OrderByDescending(f => f.Value[0])
- .ThenBy(f => f.Key)
- .ToDictionary(f => f.Key, f => f.Value);
- foreach (var car in cars)
- {
- Console.WriteLine($"{cars.Key} -> Mileage: {cars.Value[0]} kms, Fuel in the tank: {cars.Value[1]} lt.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement