Advertisement
silvana1303

message decrypter

Aug 8th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.48 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text.RegularExpressions;
  5. using System.Text;
  6.  
  7. namespace _02._Boss_Rush
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Regex regex = new Regex(@"^(\$|\%)(?<name>[A-Z][a-z]{2,})(\1): \[(?<first>[0-9]+)\]\|\[(?<second>[0-9]+)\]\|\[(?<third>[0-9]+)\]\|$");
  14.  
  15.             int times = int.Parse(Console.ReadLine());
  16.  
  17.             for (int i = 0; i < times; i++)
  18.             {
  19.                 string input = Console.ReadLine();
  20.  
  21.                 Match match = regex.Match(input);
  22.  
  23.                 if (match.Success)
  24.                 {
  25.                     string name = match.Groups["name"].Value;
  26.                     int first = int.Parse(match.Groups["first"].Value);
  27.                     int second = int.Parse(match.Groups["second"].Value);
  28.                     int third = int.Parse(match.Groups["third"].Value);
  29.  
  30.                     int[] array = { first, second, third };
  31.  
  32.                     StringBuilder output = new StringBuilder();
  33.  
  34.                     foreach (var item in array)
  35.                     {
  36.                         char j = (char)item;
  37.                         output.Append(j);
  38.                     }
  39.  
  40.                     Console.WriteLine($"{name}: {output}");
  41.  
  42.                 }
  43.                 else
  44.                 {
  45.                     Console.WriteLine("Valid message not found!");
  46.                 }
  47.             }
  48.  
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement