Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2020
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.44 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace NeedForSpeed
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int countOfCars = int.Parse(Console.ReadLine());
  12.             var carMileage = new Dictionary<string, int>();
  13.             var carFuel = new Dictionary<string, int>();
  14.             for (int i = 0; i < countOfCars; i++)
  15.             {
  16.                 string line = Console.ReadLine();
  17.                 string[] lineSplit = line.Split('|').ToArray();
  18.                 string car = lineSplit[0];
  19.                 int mileage = int.Parse(lineSplit[1]);
  20.                 int fuel = int.Parse(lineSplit[2]);
  21.                 carMileage[car] = mileage;
  22.                 carFuel[car] = fuel;
  23.             }
  24.             while (true)
  25.             {
  26.                 string command = Console.ReadLine();
  27.                 if (command == "Stop")
  28.                 {
  29.                     foreach (var car in carMileage.OrderByDescending(x=>x.Value).ThenBy(y=>y.Key))
  30.                     {
  31.                         Console.WriteLine($"{car.Key} -> Mileage: {car.Value} kms, Fuel in the tank: {carFuel[car.Key]} lt.");
  32.                     }
  33.                     return;
  34.                 }
  35.                 string[] commandSplit = command.Split(':').ToArray();
  36.                 string currentCar = commandSplit[1];              
  37.                 if (commandSplit[0] == "Drivë")
  38.                 {
  39.                     int distance = int.Parse(commandSplit[2]);
  40.                     int needFuel = int.Parse(commandSplit[3]);
  41.                     if (needFuel > carFuel[currentCar])
  42.                     {
  43.                         Console.WriteLine($"Not enough fuel to make that ride");
  44.                     }
  45.  
  46.                     else
  47.                     {
  48.                         carMileage[currentCar] += distance;
  49.                         carFuel[currentCar] -= needFuel;
  50.                         Console.WriteLine($"{currentCar} driven for {distance} kilometers. {needFuel} liters of fuel consumed");
  51.                         if (carMileage[currentCar] >= 100000)
  52.                         {
  53.                             Console.WriteLine($"Time to sell the {currentCar}!");
  54.                             carMileage.Remove(currentCar);
  55.                             carFuel.Remove(currentCar);
  56.                         }
  57.                     }
  58.                 }
  59.                 if (commandSplit[0] == "Refuel")
  60.                 {
  61.                     int fuel = int.Parse(commandSplit[2]);
  62.                     if((carFuel[currentCar]+fuel)>=75)
  63.                     {
  64.                         int differentFuel = carFuel[currentCar] - 75;
  65.                         carFuel[currentCar] = 75;
  66.                         Console.WriteLine($"{currentCar} refueled with {differentFuel} liters");
  67.                     }
  68.                 }
  69.                 if (commandSplit[0] == "Revert")
  70.                 {
  71.                     int kilometers = int.Parse(commandSplit[2]);
  72.                     carMileage[currentCar] -= kilometers;
  73.                     if (carMileage[currentCar] < 10000)
  74.                     {
  75.                         carMileage[currentCar] = 10000;
  76.                     }
  77.                     else
  78.                     {
  79.                         Console.WriteLine($"{currentCar} mileage decreased by {kilometers} kilometers");
  80.                     }
  81.                 }                
  82.             }
  83.         }
  84.     }
  85. }
  86.  
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement