Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace _04.CubicMessages
  7. {
  8. public class CubicMessages
  9. {
  10. public static void Main()
  11. {
  12. var input = Console.ReadLine();
  13. while (input != "Over!")
  14. {
  15. var m = int.Parse(Console.ReadLine());
  16. var pattern = new StringBuilder().Append(@"^\d+([a-zA-Z]{").Append(m).Append("})[^a-zA-Z]*$").ToString();
  17. var validateInput = new Regex(pattern);
  18. var match = validateInput.Match(input);
  19. if (match.Success)
  20. {
  21. var message = match.Groups[1].Value;
  22. var verrificationCode = match.Value.Replace(message, "");
  23. var output = new StringBuilder();
  24. foreach (var ch in verrificationCode)
  25. {
  26. var index = 0;
  27. if (ch >= 48 && ch <= 57)
  28. {
  29. index = int.Parse(ch.ToString());
  30. if (index >= 0 && index < message.Length)
  31. {
  32. output.Append(message[index]);
  33. }
  34. else
  35. {
  36. output.Append(' ');
  37. }
  38. }
  39. else
  40. {
  41. output.Append(' ');
  42. }
  43. }
  44. Console.ForegroundColor = ConsoleColor.Green;
  45. Console.WriteLine($"{message} == {output.ToString()}");
  46. Console.ResetColor();
  47. }
  48. else
  49. {
  50. input = Console.ReadLine();
  51. continue;
  52. }
  53. input = Console.ReadLine();
  54. }
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement