Advertisement
dragonbs

Santa's Little Helper

Mar 30th, 2023
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. internal class Program
  7. {
  8.     static void Main()
  9.     {
  10.         int key = int.Parse(Console.ReadLine());
  11.         var goodChildren = new List<string>();
  12.         string input;
  13.         while ((input = Console.ReadLine()) != "end")
  14.         {
  15.             string message = GetDecodedInput(input, key);
  16.             string regex = @"[@](?<name>[A-Za-z]+)[^@!:>-]+[!](?<behaviour>[G|N])[!]";
  17.             MatchCollection matchInfo = Regex.Matches(message, regex);
  18.  
  19.             if (matchInfo.Count == 0)
  20.                 continue;
  21.  
  22.             string childName = matchInfo[0].Groups["name"].Value;
  23.             string childBehaviour = matchInfo[0].Groups["behaviour"].Value;
  24.  
  25.             if (childBehaviour == "G")
  26.                 goodChildren.Add(childName);
  27.         }
  28.         Console.WriteLine(String.Join("\n", goodChildren));
  29.     }
  30.  
  31.     static string GetDecodedInput(string input, int key)
  32.     {
  33.         char[] decodedChars = input
  34.             .ToCharArray()
  35.             .Select(x => (char)(x - key))
  36.             .ToArray();
  37.         return String.Join("", decodedChars);
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement