petarkobakov

Message Translator

Aug 4th, 2020
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Security.Cryptography;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace Message_Translator
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. int count = int.Parse(Console.ReadLine());
  13. Regex pattern = new Regex (@"(!)(?<command>[A-Z][a-z]{2,})(\1).([[])(?<message>[A-Za-z]{8,})([]])");
  14.  
  15. for (int i = 0; i < count; i++)
  16. {
  17. string message = Console.ReadLine();
  18. Match valid = pattern.Match(message);
  19.  
  20. if (valid.Success)
  21. {
  22. string line = valid.Groups["message"].Value;
  23.  
  24. Console.Write($"{valid.Groups["command"]}: ");
  25.  
  26. foreach (var ch in line)
  27. {
  28. int number = ch;
  29.  
  30. Console.Write($"{number} ");
  31. }
  32.  
  33. Console.WriteLine();
  34. }
  35.  
  36. else
  37. {
  38. Console.WriteLine("The message is invalid");
  39. }
  40.  
  41. }
  42. }
  43. }
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment