amphibia89

04. Vehicle Park

Apr 18th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4.  
  5. class Program
  6. {
  7.     static void Main(string[] args)
  8.     {
  9. #if DEBUG
  10.         Console.SetIn(new StreamReader("../../../input.txt"));
  11. #endif
  12.         var availableVehicles = Console.ReadLine().Split().ToList();
  13.         int vehiclesSold = 0;
  14.  
  15.         string vehicleRequest = Console.ReadLine();
  16.         while (vehicleRequest != "End of customers!")
  17.         {
  18.             string[] parameters = vehicleRequest.ToLower().Split();
  19.             string currentVehicle = "" + parameters[0][0] + parameters[2];
  20.  
  21.             if (availableVehicles.Contains(currentVehicle))
  22.             {
  23.                 vehiclesSold++;
  24.                 availableVehicles.Remove(currentVehicle);
  25.  
  26.                 int vehiclePrice = currentVehicle[0] * int.Parse(parameters[2]);
  27.                 Console.WriteLine($"Yes, sold for {vehiclePrice}$");
  28.             }
  29.             else
  30.             {
  31.                 Console.WriteLine("No");
  32.             }
  33.  
  34.             vehicleRequest = Console.ReadLine();
  35.         }
  36.  
  37.         Console.WriteLine($"Vehicles left: {string.Join(", ", availableVehicles)}");
  38.         Console.WriteLine($"Vehicles sold: {vehiclesSold}");
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment