Advertisement
elena1234

Santa'sSecretHelper

Nov 28th, 2020
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.60 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5.  
  6. namespace SantasSecretHelper
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             int key = int.Parse(Console.ReadLine());
  13.             string message = string.Empty;
  14.             var dictNameAndBehaviour = new Dictionary<string, string>();
  15.  
  16.             while((message=Console.ReadLine())!="end")
  17.             {              
  18.                 string decryptMessage = string.Empty;
  19.                 for (int i = 0; i < message.Length; i++)
  20.                 {
  21.                     int decryptValue =  message[i] - key;
  22.                     decryptMessage += (char)decryptValue;
  23.                 }
  24.  
  25.                 Regex regexForNameAndBehaviour = new Regex(@"@(?<name>[A-Za-z]+(?![@\-!:>]))[^@\-!:>]*!(?<behaviour>G|N)!");
  26.                 MatchCollection matchNameAndBehaviour = regexForNameAndBehaviour.Matches(decryptMessage);
  27.                 if (regexForNameAndBehaviour.IsMatch(decryptMessage))
  28.                 {
  29.                     string name = matchNameAndBehaviour[0].Groups["name"].Value;
  30.                     string behaviour = matchNameAndBehaviour[0].Groups["behaviour"].Value;
  31.                     dictNameAndBehaviour[name] = behaviour;
  32.                 }
  33.             }
  34.  
  35.             var dictonaryWihtGoodChildren = dictNameAndBehaviour.Where(x => x.Value == "G");
  36.  
  37.             foreach (var kvp in dictonaryWihtGoodChildren )
  38.             {
  39.                 string name = kvp.Key;
  40.                 Console.WriteLine(name);
  41.             }        
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement