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 n = int.Parse(Console.ReadLine());
- for (int i = 0; i < n; i++)
- {
- string message = Console.ReadLine();
- Regex regex = new Regex(@"(\*|@)([A-Z][a-z]{2,})\1: \[(\w)\]\|\[(\w)\]\|\[(\w)\]\|$");
- bool match = regex.IsMatch(message);
- Match tag = regex.Match(message);
- string tagString = tag.Groups[2].Value;
- if (match == false)
- {
- Console.WriteLine("Valid message not found!");
- }
- else
- {
- Regex groups = new Regex(@"(\*|@)([A-Z][a-z]{2,})\1: \[(\w)\]\|\[(\w)\]\|\[(\w)\]\|$");
- Match matching = groups.Match(message);
- string firstGroup = matching.Groups[3].Value;
- string secondGroup = matching.Groups[4].Value;
- string thirdGroup = matching.Groups[5].Value;
- char firstChar = char.Parse(firstGroup);
- char secondChar = char.Parse(secondGroup);
- char thirdChar = char.Parse(thirdGroup);
- int firstValue = (int)firstChar;
- int secondValue = (int)secondChar;
- int thirdValue = (int)thirdChar;
- string stringValue = firstValue.ToString() + " " + secondValue.ToString() + " " + thirdValue.ToString();
- Console.WriteLine($"{tagString}: {stringValue}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment