Advertisement
silvana1303

need for speed

Aug 5th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.80 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text.RegularExpressions;
  5. using System.Runtime.InteropServices;
  6.  
  7. namespace _02._Boss_Rush
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int times = int.Parse(Console.ReadLine());
  14.             Dictionary<string, int> mileage = new Dictionary<string, int>();
  15.             Dictionary<string, int> fuel = new Dictionary<string, int>();
  16.  
  17.             for (int i = 0; i < times; i++)
  18.             {
  19.                 string[] input = Console.ReadLine().Split('|');
  20.                 //{car}|{mileage}|{fuel}
  21.  
  22.                 if (!mileage.ContainsKey(input[0]))
  23.                 {
  24.                     mileage[input[0]] = int.Parse(input[1]);
  25.                 }
  26.                 if (!fuel.ContainsKey(input[0]))
  27.                 {
  28.                     fuel[input[0]] = int.Parse(input[2]);
  29.                 }
  30.  
  31.             }
  32.  
  33.             string[] command = Console.ReadLine().Split(" : ");
  34.  
  35.             while (command[0] != "Stop")
  36.             {
  37.                 //•   Drive : {car} : {distance} : {fuel}
  38.  
  39.                 if (command[0] == "Drive")
  40.                 {
  41.                     int fuelLtr = int.Parse(command[3]);
  42.                     if (fuelLtr > fuel[command[1]])
  43.                     {
  44.                         Console.WriteLine("Not enough fuel to make that ride");
  45.                     }
  46.                     else
  47.                     {
  48.                         mileage[command[1]] += int.Parse(command[2]);
  49.                         fuel[command[1]] -= fuelLtr;
  50.                         Console.WriteLine($"{command[1]} driven for {command[2]} kilometers. {command[3]} liters of fuel consumed.");
  51.                     }
  52.                     if (mileage[command[1]] >= 100000)
  53.                     {
  54.                         Console.WriteLine($"Time to sell the {command[1]}!");
  55.                         mileage.Remove(command[1]);
  56.                         fuel.Remove(command[1]);
  57.                     }
  58.                 }
  59.                 if (command[0] == "Refuel")
  60.                 {
  61.                     //•   Refuel : {car} : {fuel}
  62.                     fuel[command[1]] += int.Parse(command[2]);
  63.                     if (fuel[command[1]] > 75)
  64.                     {
  65.                         //70 + 20 = 90
  66.                         //90 - 75 = 15
  67.                         //20 - 15 = need;
  68.                         int difference = fuel[command[1]] - 75;
  69.                         int need = int.Parse(command[2]) - difference;
  70.                         fuel[command[1]] = 75;
  71.                         Console.WriteLine($"{command[1]} refueled with {need} liters");
  72.                     }
  73.                     else
  74.                     {
  75.                         Console.WriteLine($"{command[1]} refueled with {int.Parse(command[2])} liters");
  76.                     }
  77.                 }
  78.                 if (command[0] == "Revert")
  79.                 {
  80.                     //•   Revert : {car} : {kilometers}
  81.                     int kilometres = int.Parse(command[2]);
  82.                     mileage[command[1]] -= kilometres;
  83.  
  84.                     if (mileage[command[1]] >= 10000)
  85.                     {
  86.                         Console.WriteLine($"{command[1]} mileage decreased by {kilometres} kilometers");
  87.                     }
  88.                     else
  89.                     {
  90.                         mileage[command[1]] = 10000;
  91.                     }
  92.                 }
  93.  
  94.                 command = Console.ReadLine().Split(" : ");
  95.             }
  96.  
  97.        
  98.             foreach (var item in mileage.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  99.             {
  100.                 Console.WriteLine($"{item.Key} -> Mileage: {item.Value} kms, Fuel in the tank: {fuel[item.Key]} lt.");
  101.             }
  102.  
  103.         }
  104.     }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement