fbinnzhivko

04.03 Vehicle Park

Apr 21st, 2016
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. internal class Program
  5. {
  6.     private static void Main()
  7.     {
  8.         List<string> vehicles = Console.ReadLine().ToLower().Split(' ').ToList();
  9.         string input = Console.ReadLine().ToLower();
  10.  
  11.         decimal vehiclesSold = 0;
  12.         while (input != "end of customers!")
  13.         {
  14.             string[] data = input.Split(' ');
  15.  
  16.             string query = data[0].ToLower()[0] + data[2];
  17.  
  18.             int wantedIndex = -1;
  19.             for (int i = 0; i < vehicles.Count; i++)
  20.             {
  21.                 if (query == vehicles[i])
  22.                 {
  23.                     wantedIndex = i;
  24.                     break;
  25.                 }
  26.             }
  27.  
  28.             if (wantedIndex == -1) { Console.WriteLine("No"); }
  29.             else
  30.             {
  31.                 string vehicle = vehicles[wantedIndex];
  32.                 int price = vehicle[0] * int.Parse(vehicle.Substring(1, vehicle.Length - 1));
  33.                 Console.WriteLine("Yes, sold for {0}$", price);
  34.                 vehiclesSold++;
  35.                 vehicles.RemoveAt(wantedIndex);
  36.             }
  37.             input = Console.ReadLine().ToLower();
  38.  
  39.  
  40.             //decimal money = (char.Parse(input.Substring(0, 1))) * decimal.Parse(data[2]);
  41.  
  42.             //bool results = Array.Exists(vehicles, element => element == (query));
  43.  
  44.             //if (results == false)
  45.             //{
  46.             //    Console.WriteLine("No");
  47.             //}
  48.             //else
  49.             //{
  50.             //    Console.WriteLine("Yes, sold for {0}$", money); vihicleSold++;
  51.  
  52.  
  53.             //    carsAvailable = carsAvailable.Except(query.Split(' ')).ToArray();
  54.  
  55.             //    final = String.Join(", ", carsAvailable);
  56.  
  57.             //    var rgx = new Regex(query);
  58.  
  59.             //}
  60.         }
  61.         Console.WriteLine("Vehicles left: {0}", string.Join(", ", vehicles));
  62.         Console.WriteLine("Vehicles sold: {0}", vehiclesSold);
  63.     }
  64. }
Add Comment
Please, Sign In to add comment