Advertisement
Guest User

Untitled

a guest
Jul 31st, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.23 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace Message_Encrypter
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int n = int.Parse(Console.ReadLine());
  11.             for (int i = 0; i < n; i++)
  12.             {
  13.                 string input = Console.ReadLine();
  14.                 string pattern = @"[*|@](?<tag>[A-Z][a-z]{2,})[*|@]: \[(?<number1>[A-Za-z])\]\|\[(?<number2>[A-Za-z])]\|\[(?<number3>[A-Za-z])\]\|$";
  15.                 var reg = new Regex(pattern);
  16.                 var match = reg.Match(input);
  17.                 if (!match.Success)
  18.                 {
  19.                     Console.WriteLine("Valid message not found!");
  20.                     continue;
  21.                 }
  22.                 else
  23.                 {
  24.                     string tag = match.Groups["tag"].Value;
  25.                     char num1 = char.Parse(match.Groups["number1"].Value);
  26.                     char num2 = char.Parse(match.Groups["number2"].Value);
  27.                     char num3 = char.Parse(match.Groups["number3"].Value);
  28.                     Console.WriteLine($"{tag}: {(int)num1} {(int)num2} {(int)num3} ");
  29.                    
  30.                 }
  31.                
  32.             }
  33.         }
  34.     }
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement