fbinnzhivko

04.04 Vehicle Park

Apr 21st, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. class Program
  5. {
  6.     static void Main()
  7.     {
  8.         var carsAvailable = Console.ReadLine().ToLower().Split(' ').ToList();
  9.         var input = Console.ReadLine().ToLower();
  10.         var carsWanted = new List<string>();
  11.         var count = 0;
  12.         while (input != "end of customers!")
  13.         {
  14.  
  15.             var typeOfVehicle = input[0];
  16.             var command = input.Split(' ').ToArray();
  17.             var seats = int.Parse(command[2]);
  18.             string wantedVehicle = typeOfVehicle + command[2];
  19.             if (carsAvailable.Contains(wantedVehicle))
  20.             {
  21.                 var price = 0;
  22.                 price = typeOfVehicle * seats;
  23.                 carsWanted.Add($"Yes, sold for {price}$");
  24.                 carsAvailable.Remove(wantedVehicle);
  25.                 count++;
  26.             }
  27.             else
  28.                 carsWanted.Add("No");
  29.  
  30.             input = Console.ReadLine().ToLower();
  31.         }
  32.  
  33.         foreach (var result in carsWanted)
  34.             Console.WriteLine(result);
  35.         Console.WriteLine("Vehicles left: " + string.Join(", ", carsAvailable));
  36.         Console.WriteLine("Vehicles sold: {0}", count);
  37.     }
  38. }
Add Comment
Please, Sign In to add comment