Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- using System.Runtime.InteropServices;
- namespace _02._Boss_Rush
- {
- class Program
- {
- static void Main(string[] args)
- {
- int times = int.Parse(Console.ReadLine());
- Dictionary<string, int> mileage = new Dictionary<string, int>();
- Dictionary<string, int> fuel = new Dictionary<string, int>();
- for (int i = 0; i < times; i++)
- {
- string[] input = Console.ReadLine().Split('|');
- //{car}|{mileage}|{fuel}
- if (!mileage.ContainsKey(input[0]))
- {
- mileage[input[0]] = int.Parse(input[1]);
- }
- if (!fuel.ContainsKey(input[0]))
- {
- fuel[input[0]] = int.Parse(input[2]);
- }
- }
- string[] command = Console.ReadLine().Split(" : ");
- while (command[0] != "Stop")
- {
- //• Drive : {car} : {distance} : {fuel}
- if (command[0] == "Drive")
- {
- int fuelLtr = int.Parse(command[3]);
- if (fuelLtr > fuel[command[1]])
- {
- Console.WriteLine("Not enough fuel to make that ride");
- }
- else
- {
- mileage[command[1]] += int.Parse(command[2]);
- fuel[command[1]] -= fuelLtr;
- Console.WriteLine($"{command[1]} driven for {command[2]} kilometers. {command[3]} liters of fuel consumed.");
- }
- if (mileage[command[1]] >= 100000)
- {
- Console.WriteLine($"Time to sell the {command[1]}!");
- mileage.Remove(command[1]);
- fuel.Remove(command[1]);
- }
- }
- if (command[0] == "Refuel")
- {
- //• Refuel : {car} : {fuel}
- fuel[command[1]] += int.Parse(command[2]);
- if (fuel[command[1]] > 75)
- {
- //70 + 20 = 90
- //90 - 75 = 15
- //20 - 15 = need;
- int difference = fuel[command[1]] - 75;
- int need = int.Parse(command[2]) - difference;
- fuel[command[1]] = 75;
- Console.WriteLine($"{command[1]} refueled with {need} liters");
- }
- else
- {
- Console.WriteLine($"{command[1]} refueled with {int.Parse(command[2])} liters");
- }
- }
- if (command[0] == "Revert")
- {
- //• Revert : {car} : {kilometers}
- int kilometres = int.Parse(command[2]);
- mileage[command[1]] -= kilometres;
- if (mileage[command[1]] >= 10000)
- {
- Console.WriteLine($"{command[1]} mileage decreased by {kilometres} kilometers");
- }
- else
- {
- mileage[command[1]] = 10000;
- }
- }
- command = Console.ReadLine().Split(" : ");
- }
- foreach (var item in mileage.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
- {
- Console.WriteLine($"{item.Key} -> Mileage: {item.Value} kms, Fuel in the tank: {fuel[item.Key]} lt.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement