Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace More_Exersises
- {
- class Program
- {
- static void Main(string[] args)
- {
- var travel = new Dictionary<string, Dictionary<string, int>>();
- string[] input = Console.ReadLine().Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
- while (input[0] != "ready")
- {
- string destination = input[0];
- string[] cityAndCapasity = input[1].Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
- for (int i = 0; i < cityAndCapasity.Length; i++)
- {
- string[] current = cityAndCapasity[i].Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
- if (travel.ContainsKey(destination) == false)
- {
- travel.Add(destination, new Dictionary<string, int>());
- if (travel[destination].ContainsKey(current[0]) == false)
- {
- travel[destination].Add(current[0], int.Parse(current[1]));
- }
- }
- else
- {
- if (travel[destination].ContainsKey(current[0]) == false)
- {
- travel[destination].Add(current[0], int.Parse(current[1]));
- }
- else
- {
- travel[destination][current[0]] += int.Parse(current[1]);
- }
- }
- }
- input = Console.ReadLine().Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
- }
- var helper = new Dictionary<string, int>();
- foreach (var item in travel)
- {
- if (helper.ContainsKey(item.Key)== false)
- {
- helper.Add(item.Key, item.Value.Values.Sum());
- }
- else
- {
- helper[item.Key] += item.Value.Values.Sum();
- }
- }
- string[] aim = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
- while (aim[0] != "travel")
- {
- int placesAvaible = 0;
- foreach (var country in helper)
- {
- if (country.Key == aim[0])
- {
- placesAvaible = country.Value;
- placesAvaible -= int.Parse(aim[1]);
- helper[aim[0]] = placesAvaible;
- if (placesAvaible >= 0)
- {
- Console.WriteLine($"{aim[0]} -> all {aim[1]} accommodated");
- break;
- }
- else
- {
- Console.WriteLine($"{aim[0]} -> all except {Math.Abs(placesAvaible)} accommodated");
- break;
- }
- }
- }
- aim = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement