mattnguyen

My Problem 2 (Final Exam 14/08/2021)

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