Advertisement
Guest User

Untitled

a guest
Jul 19th, 2017
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.00 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 dic = new Dictionary<string, Dictionary<string, int>>();
  9.  
  10.         while (true)
  11.         {
  12.             string[] curentRow = Console.ReadLine().Split(':');
  13.             if (curentRow[0] == "ready")
  14.             {
  15.                 break;
  16.             }
  17.             string country = curentRow[0];
  18.             string[] currntTransported = curentRow[1].Split(',');
  19.  
  20.             foreach (string transport in currntTransported)
  21.             {
  22.                 string[] x = transport.Split('-');
  23.                 string typeTransport = x[0];
  24.                 int capacity = int.Parse(x[1]);
  25.  
  26.                 if (!dic.ContainsKey(country))
  27.                 {
  28.                     dic[country] = new Dictionary<string, int>();
  29.                 }
  30.                 dic[country][typeTransport] = capacity;
  31.             }
  32.         }
  33.         while (true)
  34.         {
  35.             string[] cureent = Console.ReadLine().Split();
  36.             if (cureent[0] + cureent[1] == "traveltime!")
  37.             {
  38.                 break;
  39.             }
  40.             string searchedCountry = cureent[0];
  41.             int people = int.Parse(cureent[1]);
  42.  
  43.             foreach (var country in dic)
  44.             {
  45.                 int differnce = people - country.Value.Values.Sum();
  46.  
  47.                 foreach (var transport in country.Value)
  48.                 {
  49.                     if (country.Key == searchedCountry && differnce < 0)
  50.                     {
  51.                         Console.WriteLine("{0} -> all {1} accommodated", searchedCountry, people);
  52.                         break;
  53.  
  54.                     }
  55.                     if (country.Key == searchedCountry && differnce >= 0)
  56.                     {
  57.                         Console.WriteLine("{0} -> all except {1} accommodated", searchedCountry, Math.Abs(differnce));
  58.                         break;
  59.                     }
  60.                 }
  61.             }
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement