Advertisement
Guest User

Untitled

a guest
Jul 19th, 2017
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.70 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. class Program
  4. {
  5.     static void Main()
  6.     {
  7.         Dictionary<string, long> dic = new Dictionary<string, long>();
  8.  
  9.         while (true)
  10.         {
  11.             string[] curentRow = Console.ReadLine().Split(':');
  12.             if (curentRow[0] == "ready")
  13.             {
  14.                 break;
  15.             }
  16.             string country = curentRow[0];
  17.             string[] currntTransported = curentRow[1].Split(',');
  18.             long sum = 0;
  19.  
  20.             foreach (string transport in currntTransported)
  21.             {
  22.                 string[] x = transport.Split('-');
  23.                 sum += int.Parse(x[1]);
  24.             }
  25.             if (!dic.ContainsKey(country))
  26.             {
  27.                 dic[country] = 0;
  28.             }
  29.             dic[country] += sum;
  30.         }
  31.         while (true)
  32.         {
  33.             string[] cureent = Console.ReadLine().Split();
  34.             if (cureent[0] + cureent[1] == "traveltime!")
  35.             {
  36.                 break;
  37.             }
  38.             string searchedCountry = cureent[0];
  39.             int people = int.Parse(cureent[1]);
  40.  
  41.             foreach (KeyValuePair<string, long> dicCountry in dic)
  42.             {
  43.                 if (dicCountry.Key == searchedCountry && people <= dicCountry.Value)
  44.                 {
  45.                     Console.WriteLine("{0} -> all {1} accommodated", searchedCountry, people);
  46.  
  47.                 }
  48.                 if (dicCountry.Key == searchedCountry && people > dicCountry.Value)
  49.                 {
  50.                     Console.WriteLine("{0} -> all except {1} accommodated", searchedCountry, people - dicCountry.Value);
  51.                 }
  52.             }
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement