Advertisement
silvana1303

message translator

Aug 6th, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.38 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text.RegularExpressions;
  5. using System.Runtime.InteropServices;
  6. using System.Data;
  7. using System.IO;
  8. using System.Reflection.PortableExecutable;
  9.  
  10. namespace _02._Boss_Rush
  11. {
  12.     class Program
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             Regex regex = new Regex(@"!(?<command>[A-Z][a-z]{2,})!:\[(?<message>[a-zA-Z]{8,})\]");
  17.  
  18.             int times = int.Parse(Console.ReadLine());
  19.  
  20.             List<int> output1 = new List<int>();
  21.  
  22.             for (int i = 0; i < times; i++)
  23.             {
  24.                 string input = Console.ReadLine();
  25.  
  26.                 Match match = regex.Match(input);
  27.  
  28.                 if (match.Success)
  29.                 {
  30.                     string command = match.Groups["command"].Value;
  31.                     string message = match.Groups["message"].Value;
  32.  
  33.                     char[] chars = message.ToCharArray();
  34.  
  35.                     foreach (var item in chars)
  36.                     {
  37.                         int j = item;
  38.                         output1.Add(j);
  39.                     }
  40.  
  41.                     Console.WriteLine($"{command}: {string.Join(" ", output1)}");
  42.  
  43.                 }
  44.                 else
  45.                 {
  46.                     Console.WriteLine("The message is invalid");
  47.                 }
  48.             }
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement