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.RegularExpressions;
- using System.Numerics;
- namespace Exam_Pr03
- {
- class Program
- {
- static void Main()
- {
- Dictionary<string, int> townToTimes = new Dictionary<string, int>();
- Dictionary<string, ulong> townToPassengers = new Dictionary<string, ulong>();
- while (true)
- {
- var input = Console.ReadLine();
- if(input == "Slide rule")
- {
- break;
- }
- string[] arrForTown = input.Split(new[] { ':'}, StringSplitOptions.RemoveEmptyEntries);
- string town = arrForTown[0];
- string[] arrForTime = input.Split(new[] { ':', '>'}, StringSplitOptions.RemoveEmptyEntries);
- string rawTime = arrForTime[1];
- rawTime = rawTime.Trim('-');
- int time;
- string ambush = "";
- ulong passengers = ulong.Parse(arrForTime[2]);
- if (int.TryParse(rawTime, out time))
- {
- time = int.Parse(rawTime);
- }
- else
- {
- ambush = rawTime;
- }
- if (ambush != "")
- {
- if(townToTimes.ContainsKey(town))
- {
- townToTimes[town] = 0;
- townToPassengers[town] -= passengers;
- }
- }
- else
- {
- if(!townToTimes.ContainsKey(town))
- {
- townToTimes.Add(town, time);
- townToPassengers.Add(town, passengers);
- }
- else
- {
- if(townToTimes[town] == 0 || townToTimes[town] > time)
- {
- townToTimes[town] = time;
- }
- townToPassengers[town] += passengers;
- }
- }
- }
- foreach(var entry in townToTimes.OrderBy(kvp => kvp.Value).ThenBy(kvp => kvp.Key))
- {
- string town = entry.Key;
- int time = entry.Value;
- ulong passengersCount = townToPassengers[town];
- if(time < 1 || passengersCount <= 1)
- {
- continue;
- }
- Console.WriteLine($"{town} -> Time: {time} -> Passengers: {passengersCount}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement