evgeni_tsn

Untitled

Feb 28th, 2016
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.40 KB | None | 0 0
  1. namespace Problem4
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.     using System.Text.RegularExpressions;
  7.  
  8.     public class Program
  9.     {
  10.         public static void Main()
  11.         {
  12.             SortedDictionary<string, SortedDictionary<string, List<string>>> mainInfo = new SortedDictionary<string, SortedDictionary<string, List<string>>>();
  13.             var rgx = new Regex(@"#([A-z]+):\s*@([A-z]+)\s*(\d+:\d+)");
  14.             int times = int.Parse(Console.ReadLine());
  15.             for (int i = 0; i < times; i++)
  16.             {
  17.                 string line = Console.ReadLine();
  18.                 var match = rgx.Match(line);
  19.                 if (match.Success)
  20.                 {
  21.                     var person = match.Groups[1].Value.Trim();
  22.                     var town = match.Groups[2].Value.Trim();
  23.                     var time = match.Groups[3].Value.Trim();
  24.                     var splitTime = time.Split(':');
  25.                     int hours = int.Parse(splitTime[0]);
  26.                     int minutes = int.Parse(splitTime[1]);
  27.                     if ((hours >= 0 && hours <= 23) && (minutes >= 0 && minutes <= 59))
  28.                     {
  29.  
  30.                         if (!mainInfo.ContainsKey(town))
  31.                         {
  32.                             mainInfo[town] = new SortedDictionary<string, List<string>>();
  33.                         }
  34.  
  35.  
  36.                         if (!mainInfo[town].ContainsKey(person))
  37.                         {
  38.                             mainInfo[town][person] = new List<string>();
  39.                         }
  40.  
  41.                         mainInfo[town][person].Add(time);
  42.                     }
  43.                 }
  44.             }
  45.  
  46.             List<string> whichCities = Console.ReadLine().Split(',').ToList();
  47.  
  48.             foreach (var pair in mainInfo)
  49.             {
  50.                 if (whichCities.Contains(pair.Key))
  51.                 {
  52.                     int counter = 0;
  53.                     Console.WriteLine("{0}:", pair.Key);
  54.                     foreach (var info in pair.Value)
  55.                     {
  56.                         counter++;
  57.                         Console.Write("{1}. {0} -> ", info.Key, counter);
  58.                         var orderedEnumerable = info.Value.OrderBy(c => c);
  59.                         Console.WriteLine(string.Join(", ", orderedEnumerable));
  60.                     }
  61.                 }
  62.             }
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment