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