Advertisement
AndrianaTodorova

Untitled

Oct 31st, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.72 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace _02.HornetComm
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             var input = Console.ReadLine();
  15.             Dictionary<string, List<string>> privateMessages = new Dictionary<string, List<string>>();
  16.             Dictionary<string, string> broadcast = new Dictionary<string, string>();
  17.             string patternMessage = @"\b([0-9]+) <-> ([^\d\W]+\b)";
  18.             string patternBroadcast = @"^([^\d]+) <-> ([A-Za-z0-9]+)";
  19.             while (input != "Hornet is Green")
  20.             {
  21.  
  22.  
  23.                 foreach (Match m in Regex.Matches(input, patternMessage))
  24.                 {
  25.                     if (!privateMessages.ContainsKey(m.Groups[1].Value))
  26.                     {
  27.                         privateMessages.Add(m.Groups[1].Value, new List<string>());
  28.                         privateMessages[m.Groups[1].Value].Add(m.Groups[2].Value);
  29.                     }
  30.                     else
  31.                     {
  32.                         privateMessages[m.Groups[1].Value].Add(m.Groups[2].Value);
  33.                     }
  34.  
  35.  
  36.                 }
  37.                 foreach (Match b in Regex.Matches(input, patternBroadcast))
  38.                 {
  39.                     broadcast.Add(b.Groups[1].Value, b.Groups[2].Value);
  40.                 }
  41.                 var reversed = string.Empty;
  42.                 foreach (var item in privateMessages)
  43.                 {
  44.                     reversed = item.Key.ToString().Reverse().ToString();
  45.                 }
  46.  
  47.                 input = Console.ReadLine();
  48.             }
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement