Advertisement
valkata

03. Travel Company View code

Jul 11th, 2017
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.33 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 travelCompany
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Dictionary<string, Dictionary<string, int>> capacity = new Dictionary<string, Dictionary<string, int>>();
  14.  
  15.             string[] input = Console.ReadLine().Split(new char[] { ':', ',', '-' });
  16.             while(!(input[0] == "ready"))
  17.             {
  18.                 string country = input[0];
  19.                 if (!(capacity.ContainsKey(country)))
  20.                 {
  21.                     capacity.Add(country, new Dictionary<string, int>());
  22.                     for (int i = 1; i < input.Length; i++)
  23.                     {
  24.                         if (i % 2 == 1)
  25.                         {
  26.                             if (!(capacity[country].ContainsKey(input[i])))
  27.                             {
  28.                                 capacity[country].Add(input[i], int.Parse(input[i + 1]));
  29.                             }
  30.                           /*else
  31.                             {
  32.                                 capacity[country][input[i]] += int.Parse(input[i + 1]);
  33.                             }
  34.                           */
  35.                            
  36.                         }
  37.                     }
  38.                 }
  39.                 else
  40.                 {
  41.                     for (int i = 1; i < input.Length; i++)
  42.                     {
  43.                         if (i % 2 == 1)
  44.                         {
  45.                             if (!(capacity[country].ContainsKey(input[i])))
  46.                             {
  47.                                 capacity[country].Add(input[i], int.Parse(input[i + 1]));
  48.                             }
  49.                             else
  50.                             {
  51.                                 capacity[country][input[i]] = int.Parse(input[i + 1]);
  52.                             }
  53.                            
  54.                         }
  55.                     }
  56.                 }
  57.                 input = Console.ReadLine().Split(new char[] { ':', ',', '-' });
  58.             }
  59.             string destination = Console.ReadLine();
  60.             while(!(destination.Equals("travel time!")))
  61.             {
  62.                 string[] country = destination.Split().ToArray();
  63.                 int people = int.Parse(country[1]);
  64.                 int full = people;
  65.                
  66.                 if (capacity.ContainsKey(country[0]))
  67.                 {
  68.  
  69.                     int total = 0;
  70.                     Dictionary<string, int> transport = capacity[country[0]];                      
  71.                     foreach (KeyValuePair<string, int> type in transport)
  72.                     {
  73.                         total += type.Value;
  74.                     }
  75.                     total = total - people;
  76.                     if (total < 0)
  77.                     {
  78.                         Console.WriteLine($"{country[0]} -> all except {Math.Abs(total)} accommodated");
  79.                        
  80.                     }
  81.                     else
  82.                     {
  83.                         Console.WriteLine($"{country[0]} -> all {full} accommodated");
  84.                     }
  85.  
  86.                 }
  87.                 destination = Console.ReadLine();
  88.             }          
  89.         }
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement