Advertisement
Guest User

Untitled

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