Advertisement
dinko_dt

Untitled

Mar 28th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace MessageDecrypter
  8. {
  9. class MessageDecrypter
  10. {
  11. static void Main()
  12. {
  13.  
  14. int count = int.Parse(Console.ReadLine());
  15. string pattern = @"^([$%])([A-Z][a-z]{2,})([$%])\:\s\[(\d+)\]\|\[(\d+)\]\|\[(\d)+\]\|$";
  16.  
  17.  
  18. for (int i = 0; i < count; i++)
  19. {
  20. string input = Console.ReadLine();
  21. Match match = Regex.Match(input, pattern);
  22.  
  23. if (match.Success)
  24. {
  25. string openingTag = match.Groups[1].Value;
  26. string closingTag = match.Groups[3].Value;
  27.  
  28. if (openingTag == closingTag)
  29. {
  30. string tagName = match.Groups[2].Value;
  31. string message = "";
  32.  
  33. for (int j = 4; j < match.Groups.Count; j++)
  34. {
  35. int value = int.Parse(match.Groups[j].Value);
  36. message += (char)value;
  37. }
  38.  
  39. Console.WriteLine($"{tagName}: {message}");
  40. }
  41. else
  42. {
  43. Console.WriteLine("Valid message not found!");
  44. }
  45. }
  46. else
  47. {
  48. Console.WriteLine("Valid message not found!");
  49. }
  50. }
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement