Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace zada4a4
- {
- class Program
- {
- static void Main(string[] args)
- {
- var allCities = new Dictionary<string, KeyValuePair<int, long>>();
- var input = string.Empty;
- while (!(input = Console.ReadLine()).Equals("Slide rule"))
- {
- var tokens = input.Split(new[] { ":", "->" }, StringSplitOptions.RemoveEmptyEntries);
- var city = tokens[0];
- var populationCount = int.Parse(tokens[2]);
- if (tokens[1].Equals("ambush"))
- {
- if (allCities.ContainsKey(city))
- {
- var currentCount = allCities[city].Value;
- currentCount -= populationCount;
- if (currentCount<0)
- {
- currentCount = 0;
- }
- allCities[city] = new KeyValuePair<int, long>(0, currentCount);
- }
- }
- else
- {
- var time = int.Parse(tokens[1]);
- if (!allCities.ContainsKey(city))
- {
- allCities.Add(city, new KeyValuePair<int, long>(time, populationCount));
- }
- else
- {
- var currentCount = allCities[city].Value;
- var currentTime = allCities[city].Key;
- currentCount += populationCount;
- if (currentTime == 0 || currentTime > time)
- {
- currentTime = time;
- }
- allCities[city] = new KeyValuePair<int, long>(currentTime, currentCount);
- }
- }
- }
- foreach (var city in allCities.OrderBy(x => x.Value.Key).ThenBy(x => x.Key))
- {
- if (allCities[city.Key].Key == 0 || allCities[city.Key].Value == 0)
- {
- continue;
- }
- Console.WriteLine($"{city.Key} -> Time: {city.Value.Key} -> Passengers: {city.Value.Value}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement