Advertisement
YavorGrancharov

Travel_Company(copy)(dict)

Jul 13th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.59 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Travel_Company
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Dictionary<string, Dictionary<string, int>> stock = new Dictionary<string, Dictionary<string, int>>();
  14.             string[] input = Console.ReadLine().Split(new string[] {":"}, StringSplitOptions.RemoveEmptyEntries);
  15.  
  16.             while (input[0] != "ready")
  17.             {
  18.                 string city = input[0];
  19.                 string[] vehicleType = input[1].Split('-', ',');
  20.  
  21.                 if (!stock.ContainsKey(city))
  22.                 {
  23.                     stock.Add(city, new Dictionary<string, int>());
  24.                 }
  25.                 for (int i = 0; i < vehicleType.Length; i+=2)
  26.                 {
  27.                     string vehicle = vehicleType[i];
  28.                     int capacity = int.Parse(vehicleType[i + 1]);
  29.  
  30.                     if (!stock[city].ContainsKey(vehicle))
  31.                     {
  32.                         stock[city].Add(vehicle, capacity);
  33.                     }
  34.                     else
  35.                     {
  36.                         stock[city][vehicle] = capacity;
  37.                     }
  38.                 }
  39.                 input = Console.ReadLine().Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
  40.             }
  41.             string[] secondInput = Console.ReadLine().Split(' ');
  42.  
  43.             while (secondInput[0] != "travel")
  44.             {
  45.                 string city = secondInput[0];
  46.                 int people = int.Parse(secondInput[1]);
  47.  
  48.                 foreach (KeyValuePair<string, Dictionary<string, int>> offer in stock)
  49.                 {
  50.                     string town = offer.Key;
  51.                     var vehicleCapacity = offer.Value;
  52.                     int sum = 0;
  53.  
  54.                     if (city == town)
  55.                     {
  56.                         foreach (var item in vehicleCapacity)
  57.                         {
  58.                             sum += item.Value;
  59.                         }
  60.                         if (sum >= people)
  61.                         {
  62.                             Console.WriteLine($"{city} -> all {people} accommodated");
  63.                         }
  64.                         else
  65.                         {
  66.                             Console.WriteLine($"{city} -> all except {people - sum} accommodated");
  67.                         }
  68.                     }
  69.                 }
  70.                 secondInput = Console.ReadLine().Split(' ');
  71.             }
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement