Advertisement
Guest User

CubicMessages100

a guest
Apr 27th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 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. using System.Threading.Tasks;
  7.  
  8. namespace _4.CubicMessages
  9. {
  10. class CubicMessages
  11. {
  12. static void Main()
  13. {
  14. string code = Console.ReadLine();
  15. StringBuilder builder = new StringBuilder();
  16.  
  17. while (!code.Equals("Over!"))
  18. {
  19. int decryptorSize = int.Parse(Console.ReadLine());
  20. Regex check = new Regex(@"^(\d+)([a-zA-Z]+)([^a-zA-Z]*)$");
  21.  
  22. if (check.Match(code).Success && check.Match(code).Groups[2].Length == decryptorSize)
  23. {
  24. Match matches = check.Match(code);
  25. string val = matches.Groups[1].Value;
  26. for (int i = 0; i < val.Length; i++)
  27. {
  28. if (int.Parse(val[i] + "") >= 0 && int.Parse(val[i] + "") < decryptorSize)
  29. {
  30. builder.Append(matches.Groups[2].Value[int.Parse(val[i] + "")]);
  31. }
  32. else
  33. {
  34. builder.Append(" ");
  35. }
  36. }
  37. string val2 = matches.Groups[3].Value;
  38. int[] nums = getVal2(val2);
  39. for (int i = 0; i < val2.Length; i++)
  40. {
  41. if (nums[i] >= 0 && nums[i] < decryptorSize)
  42. {
  43. builder.Append(matches.Groups[2].Value[nums[i]].ToString());
  44. }
  45. else
  46. {
  47. builder.Append(" ");
  48. }
  49. }
  50. Console.WriteLine("{0} == {1}", matches.Groups[2].Value,builder.ToString());
  51. }
  52. code = Console.ReadLine();
  53. builder = new StringBuilder();
  54. }
  55. }
  56.  
  57. private static int[] getVal2(string val2)
  58. {
  59. char[] a = val2.ToCharArray();
  60. int[] b = new int[a.Length];
  61. for (int i = 0; i < a.Length; i++)
  62. {
  63. if (char.IsDigit(a[i]))
  64. {
  65. b[i] = int.Parse(a[i] + "");
  66. }
  67. else
  68. {
  69. b[i] = -1;
  70. }
  71. }
  72. return b;
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement