Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace ConsoleApp4
- {
- class Program
- {
- static void Main(string[] args)
- {
- int count = int.Parse(Console.ReadLine());
- for (int i = 1; i <= count; i++)
- {
- string result = "";
- string message = Console.ReadLine();
- string[] tokens = message.Split(": ").ToArray();
- string tag = tokens[0];
- string numbers = tokens[1];
- Regex regex = new Regex(@"^(\$|%)[A-Z][a-z]+\1: \[\d+\]\|\[\d+\]\|\[\d+\]\|$");
- bool match = regex.IsMatch(message);
- if (match == false)
- {
- result = "Valid message not found!";
- Console.WriteLine(result);
- }
- else
- {
- Regex groups = new Regex(@"^(\$|%)[A-Z][a-z]+\1: \[(\d+)\]\|\[(\d+)\]\|\[(\d+)\]\|$");
- Match matching = groups.Match(message);
- string firstNumGroup = matching.Groups[2].Value;
- string secondNumGroup = matching.Groups[3].Value;
- string thirdNumGroup = matching.Groups[4].Value;
- int firstNumber = int.Parse(firstNumGroup);
- int secondNumber = int.Parse(secondNumGroup);
- int thirdNumber = int.Parse(thirdNumGroup);
- string oldChar1 = firstNumber.ToString();
- string oldChar2 = secondNumber.ToString();
- string oldChar3 = thirdNumber.ToString();
- char newChar = (char)firstNumber;
- string newChar1 = newChar.ToString();
- char new2Char = (char)secondNumber;
- string new2Char2 = new2Char.ToString();
- char new3Char = (char)thirdNumber;
- string new3Char3 = new3Char.ToString();
- numbers = numbers.Replace(oldChar1, newChar1);
- numbers = numbers.Replace(oldChar2, new2Char2);
- numbers = numbers.Replace(oldChar3, new3Char3);
- string decryptedMsg = newChar1 + new2Char2 + new3Char3;
- string newTag = tag.Remove(0, 1);
- newTag = newTag.Remove(newTag.Length - 1, 1);
- Console.WriteLine($"{newTag}: {decryptedMsg}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment