Advertisement
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 MessageDecrypter
- {
- class MessageDecrypter
- {
- static void Main()
- {
- int count = int.Parse(Console.ReadLine());
- string pattern = @"^([$%])([A-Z][a-z]{2,})([$%])\:\s\[(\d+)\]\|\[(\d+)\]\|\[(\d)+\]\|$";
- for (int i = 0; i < count; i++)
- {
- string input = Console.ReadLine();
- Match match = Regex.Match(input, pattern);
- if (match.Success)
- {
- string openingTag = match.Groups[1].Value;
- string closingTag = match.Groups[3].Value;
- if (openingTag == closingTag)
- {
- string tagName = match.Groups[2].Value;
- string message = "";
- for (int j = 4; j < match.Groups.Count; j++)
- {
- int value = int.Parse(match.Groups[j].Value);
- message += (char)value;
- }
- Console.WriteLine($"{tagName}: {message}");
- }
- else
- {
- Console.WriteLine("Valid message not found!");
- }
- }
- else
- {
- Console.WriteLine("Valid message not found!");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement