kvadrat4o

HornetCom

Jul 6th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.83 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Text.RegularExpressions;
  7.  
  8. namespace HornetComm
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             SortedDictionary<string, string> privates = new SortedDictionary<string, string>();
  15.             SortedDictionary<string, string> broadcasts = new SortedDictionary<string, string>();
  16.             var privatesRegex = new Regex(@"\b\d+ <-> \b([a-zA-Z0-9]+)");
  17.             var broadcastsRegex = new Regex(@"([^\d]+) <-> ([a-zA-Z0-9]+)?");
  18.             var codes = new List<string>();
  19.             var freqs = new List<string>();
  20.             var line = Console.ReadLine();
  21.             while (true)
  22.             {
  23.                 if (line == "Hornet is Green")
  24.                 {
  25.                     foreach (var prod in broadcasts)
  26.                     {
  27.                         Console.WriteLine("Broadcasts:");
  28.                         Console.WriteLine("{0}->{1}",prod.Key,prod.Value);
  29.                     }
  30.                     foreach (var privat in privates)
  31.                     {
  32.                         Console.WriteLine("Messages:");
  33.                         Console.WriteLine("{0}->{1}", privat.Key, privat.Value);
  34.                     }  
  35.                 }
  36.                 var input = line.Split(' ').ToList();
  37.                 var matchBroadcasdtTrue = broadcastsRegex.Match(line);
  38.                 var matchPrivateTrue = privatesRegex.Match(line);
  39.                 if (matchBroadcasdtTrue.Success && !broadcasts.ContainsKey(input[0]))
  40.                 {
  41.                     broadcasts.Add(input[0], input[2]);
  42.                 }
  43.                 if (matchPrivateTrue.Success && !privates.ContainsKey(input[0]))
  44.                 {
  45.                     privates.Add(input[0], input[2]);
  46.                 }
  47.                 codes = privates.Keys.ToList();
  48.                 freqs = broadcasts.Values.ToList();
  49.                 for (int i = 0; i < codes.Count; i++)
  50.                 {
  51.                     codes[i] = codes[i].Reverse().ToString();
  52.                     //codes[i] = privates.Keys[i];
  53.                 }
  54.                 for (int i = 0; i < freqs.Count; i++)
  55.                 {
  56.                     var freq = freqs[i];
  57.                     for (int j = 0; j < freq.Length; j++)
  58.                     {
  59.                         if (Char.IsUpper(freq[j]))
  60.                         {
  61.                             Char.ToLower(freq[j]);
  62.                         }
  63.                         else
  64.                         {
  65.                             Char.ToUpper(freq[j]);
  66.                         }
  67.                     }
  68.                 }
  69.                
  70.                 input = line.Split(' ').ToList();
  71.             }
  72.             line = Console.ReadLine();
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment