Advertisement
Guest User

Untitled

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