knoteva

02. Message Encrypter

Aug 5th, 2019
97
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.Text.RegularExpressions;
  3.  
  4. namespace _02._Program
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int n = int.Parse(Console.ReadLine());
  11.  
  12.             var regex = @"([@*])(?<command>[A-Z]{1,1}[a-z]{2,})(\1): \[(?<firstGroup>[A-Za-z])\]\|\[(?<secondGroup>[A-Za-z])\]\|\[(?<thirdGroup>[A-Za-z])\]\|$";
  13.             for (int i = 0; i < n; i++)
  14.             {
  15.                 string message = Console.ReadLine();
  16.                 Match m = Regex.Match(message, regex);
  17.  
  18.                 if (m.Success)
  19.                 {
  20.                     string command = m.Groups["command"].Value;
  21.                     var firstGroup = Convert.ToChar(m.Groups["firstGroup"].Value);
  22.                     var secondGroup = Convert.ToChar(m.Groups["secondGroup"].Value);
  23.                     var thirdGroup = Convert.ToChar(m.Groups["thirdGroup"].Value);
  24.                     Console.WriteLine($"{command}: {(int)firstGroup} {(int)secondGroup} {(int)thirdGroup}");
  25.                 }
  26.                 else
  27.                 {
  28.                     Console.WriteLine($"Valid message not found!");
  29.                 }
  30.             }
  31.         }
  32.     }
  33. }
Add Comment
Please, Sign In to add comment