Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4.  
  5. namespace _02.RobotCommunication
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string input = Console.ReadLine();
  12.  
  13. var charToWord = new List<string>();
  14.  
  15. while (true)
  16. {
  17. if (input == "Report")
  18. {
  19. break;
  20. }
  21.  
  22. string pattern = @"(?:[\\_\\,])[A-Za-z]+[0-9]";
  23.  
  24. var matches = Regex.Matches(input, pattern);
  25.  
  26. charToWord = new List<string>();
  27.  
  28.  
  29. foreach (var mach in matches)
  30. {
  31. string result = mach.ToString();
  32.  
  33. char num = result[result.Length - 1];
  34.  
  35. int number = (int)Char.GetNumericValue(num);
  36.  
  37. var collection = new List<int>();
  38.  
  39. string toString = string.Empty;
  40.  
  41. if (result[0] == ',')
  42. {
  43. for (int i = 1; i < result.Length - 1; i++)
  44. {
  45. collection.Add(result[i]);
  46. }
  47.  
  48. for (int i = 0; i < collection.Count; i++)
  49. {
  50. collection[i] += number;
  51. }
  52.  
  53. for (int i = 0; i < collection.Count; i++)
  54. {
  55. var chars = Convert.ToChar(collection[i]);
  56. toString += chars;
  57. }
  58. charToWord.Add(toString);
  59. }
  60. else if (result[0] == '_')
  61. {
  62. for (int i = 1; i < result.Length - 1; i++)
  63. {
  64. collection.Add(result[i]);
  65. }
  66.  
  67. for (int i = 0; i < collection.Count; i++)
  68. {
  69. collection[i] -= number;
  70. }
  71.  
  72. for (int i = 0; i < collection.Count; i++)
  73. {
  74. var chars = Convert.ToChar(collection[i]);
  75. toString += chars;
  76. }
  77. charToWord.Add(toString);
  78. }
  79. }
  80. if (charToWord.Count > 0)
  81. {
  82. Console.WriteLine(string.Join(" ", charToWord));
  83. }
  84.  
  85. input = Console.ReadLine();
  86. }
  87. }
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement