Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text.RegularExpressions;
- using System.Text;
- namespace problem02
- {
- class Program
- {
- static void Main(string[] args)
- {
- int countOfMessages = int.Parse(Console.ReadLine());
- string pattern = @"^(\$|%)([A-Z][a-z]{2,})\1: \[(\d+)\]\|\[(\d+)\]\|\[(\d+)\]\|$";
- for (int i = 0; i < countOfMessages; i++)
- {
- string text = Console.ReadLine();
- Match match = Regex.Match(text,pattern);
- if(match.Length>0)
- {
- string name = match.Groups[2].Value;
- char firstSymbol = (char)int.Parse(match.Groups[3].Value);
- char secondSymbol = (char)int.Parse(match.Groups[4].Value);
- char triedSymbol = (char)int.Parse(match.Groups[5].Value);
- StringBuilder message = new StringBuilder();
- message.Append(firstSymbol);
- message.Append(secondSymbol);
- message.Append(triedSymbol);
- Console.WriteLine($"{name}: {message}");
- }
- else
- {
- Console.WriteLine("Valid message not found!");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment