Advertisement
Guest User

Travel Company

a guest
Jul 12th, 2017
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.52 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 TravelCompany
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             bool readyMode = false;
  14.             var citiesAndTransport = new Dictionary<string, Dictionary<string, int>>();
  15.             var citiesAndTourists = new Dictionary<string, int>();
  16.             while (true)
  17.             {
  18.                 string intro = Console.ReadLine();
  19.                 if (intro == "travel time!")
  20.                     break;
  21.                 if (intro == "ready")
  22.                 {
  23.                     readyMode = true;
  24.                     continue;
  25.                 }
  26.                 if (readyMode == false)
  27.                 {
  28.                     string city = intro.Split(':')[0];
  29.                     string[] transports = intro.Split(':')[1].Split(',');
  30.                     for(int br = 0; br < transports.Length; br++)
  31.                     {
  32.                         string vehicle = transports[br].Split('-')[0];
  33.                         int capacity = int.Parse(transports[br].Split('-')[1]);
  34.                         if (!citiesAndTransport.ContainsKey(city))
  35.                             citiesAndTransport.Add(city, new Dictionary<string, int>());
  36.                         if (!citiesAndTransport[city].ContainsKey(vehicle))
  37.                             citiesAndTransport[city].Add(vehicle, capacity);
  38.                         citiesAndTransport[city][vehicle] = capacity;
  39.                     }
  40.                 }else
  41.                 {
  42.                     string city = intro.Split(' ')[0];
  43.                     int tourists = int.Parse(intro.Split(' ')[1]);
  44.                     citiesAndTourists[city]=tourists;
  45.                 }
  46.             }
  47.             int touristsInCity, sumOfAllPlaces;
  48.             foreach (var city in citiesAndTourists.Keys)
  49.             {
  50.                 touristsInCity = sumOfAllPlaces = 0;
  51.                 touristsInCity = citiesAndTourists[city];
  52.                 foreach (var item in citiesAndTransport[city])
  53.                 {
  54.                     sumOfAllPlaces = sumOfAllPlaces + item.Value;
  55.                 }
  56.                 if (sumOfAllPlaces >= touristsInCity)
  57.                     Console.WriteLine($"{city} -> all {touristsInCity} accommodated");
  58.                 else if(sumOfAllPlaces<touristsInCity)
  59.                     Console.WriteLine($"{city} -> all except {touristsInCity-sumOfAllPlaces} accommodated");
  60.             }
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement