Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text.RegularExpressions;
- namespace MessageEncrypter
- {
- class Program
- {
- static void Main(string[] args)
- {
- int number = int.Parse(Console.ReadLine());
- for (int i = 0; i < number; i++)
- {
- string input = Console.ReadLine();
- string firstPattern = @"[@](?<tag>[A-Z][a-z]{2,})[@]: \[(?<firstNumber>[A-Za-z])\]\|\[(?<secondNumber>[A-Za-z])]\|\[(?<thirdNumber>[A-Za-z])\]\|$";
- string secondPattern = @"[*](?<tag>[A-Z][a-z]{2,})[*]: \[(?<firstNumber>[A-Za-z])\]\|\[(?<secondNumber>[A-Za-z])]\|\[(?<thirdNumber>[A-Za-z])\]\|$";
- var firstRegex = new Regex(firstPattern);
- var secondRegex = new Regex(secondPattern);
- var firstMatch = firstRegex.Match(input);
- var secondMatch = secondRegex.Match(input);
- if (firstMatch.Success)
- {
- string tag = firstMatch.Groups["tag"].Value;
- char firstNumber = char.Parse(firstMatch.Groups["firstNumber"].Value);
- char secondNumber = char.Parse(firstMatch.Groups["secondNumber"].Value);
- char thirdNumber = char.Parse(firstMatch.Groups["thirdNumber"].Value);
- Console.WriteLine($"{tag}: {(int)firstNumber} {(int)secondNumber} {(int)thirdNumber} ");
- } else if (secondMatch.Success)
- {
- string tag = secondMatch.Groups["tag"].Value;
- char firstNumber = char.Parse(secondMatch.Groups["firstNumber"].Value);
- char secondNumber = char.Parse(secondMatch.Groups["secondNumber"].Value);
- char thirdNumber = char.Parse(secondMatch.Groups["thirdNumber"].Value);
- Console.WriteLine($"{tag}: {(int)firstNumber} {(int)secondNumber} {(int)thirdNumber} ");
- }
- else
- {
- Console.WriteLine("Valid message not found!");
- continue;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement