Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace travelCompany
- {
- class travelCompany
- {
- static void Main(string[] args)
- {
- Dictionary<string, Dictionary<string, int>> capacity = new Dictionary<string, Dictionary<string, int>>();
- string[] input = Console.ReadLine().Split(new char[] { ':', ',', '-' });
- while(!(input[0] == "ready"))
- {
- string country = input[0];
- if (!(capacity.ContainsKey(country)))
- {
- capacity.Add(country, new Dictionary<string, int>());
- for (int i = 1; i < input.Length; i++)
- {
- if (i % 2 == 1)
- {
- if (!(capacity[country].ContainsKey(input[i])))
- {
- capacity[country].Add(input[i], int.Parse(input[i + 1]));
- }
- /*else
- {
- capacity[country][input[i]] += int.Parse(input[i + 1]);
- }
- */
- }
- }
- }
- else
- {
- for (int i = 1; i < input.Length; i++)
- {
- if (i % 2 == 1)
- {
- if (!(capacity[country].ContainsKey(input[i])))
- {
- capacity[country].Add(input[i], int.Parse(input[i + 1]));
- }
- else
- {
- capacity[country][input[i]] = int.Parse(input[i + 1]);
- }
- }
- }
- }
- input = Console.ReadLine().Split(new char[] { ':', ',', '-' });
- }
- string destination = Console.ReadLine();
- while(!(destination.Equals("travel time!")))
- {
- string[] country = destination.Split().ToArray();
- int people = int.Parse(country[1]);
- int full = people;
- if (capacity.ContainsKey(country[0]))
- {
- int total = 0;
- Dictionary<string, int> transport = capacity[country[0]];
- foreach (KeyValuePair<string, int> type in transport)
- {
- total += type.Value;
- }
- total = total - people;
- if (total < 0)
- {
- Console.WriteLine($"{country[0]} -> all except {Math.Abs(total)} accommodated");
- }
- else
- {
- Console.WriteLine($"{country[0]} -> all {full} accommodated");
- }
- }
- destination = Console.ReadLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement