IPetrov007

Proba

Apr 16th, 2017
136
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. 2
  3. using System.Collections.Generic;
  4. 3
  5. using System.Linq;
  6. 4
  7. using System.Text;
  8. 5
  9. using System.Text.RegularExpressions;
  10. 6
  11. using System.Threading.Tasks;
  12. 7
  13.  
  14. 8
  15. namespace _04_WinningTicket
  16. 9
  17. {
  18. 10
  19. class Program
  20. 11
  21. {
  22. 12
  23. static void Main(string[] args)
  24. 13
  25. {
  26. 14
  27. var haveValidSimbols = "([$@#^])\\1{5,}";
  28. 15
  29.  
  30. 16
  31. var tickets = Console.ReadLine()
  32. 17
  33. .Split(',')
  34. 18
  35. .Select(x => x.Trim())
  36. 19
  37. .ToArray();
  38. 20
  39. var leftPart = "";
  40. 21
  41. var rightPatr = "";
  42. 22
  43.  
  44. 23
  45. Regex regex = new Regex(haveValidSimbols);
  46. 24
  47.  
  48. 25
  49. foreach (var ticket in tickets)
  50. 26
  51. {
  52. 27
  53.  
  54. 28
  55. if (ticket.Length != 20)
  56. 29
  57. {
  58. 30
  59. Console.WriteLine("invalid ticket");
  60. 31
  61. continue;
  62. 32
  63. }
  64. 33
  65.  
  66. 34
  67. leftPart = ticket.Substring(0, ticket.Length / 2);
  68. 35
  69. rightPatr = ticket.Substring(ticket.Length / 2);
  70. 36
  71.  
  72. 37
  73. var leftMatch = regex.Match(leftPart);
  74. 38
  75. var rightMatch = regex.Match(rightPatr);
  76. 39
  77.  
  78. 40
  79.  
  80. 41
  81. if (leftMatch.Success && rightMatch.Success)// && leftMatch == rightMatch)
  82. 42
  83. {
  84. 43
  85. var counter = Math.Min(leftMatch.Length, rightMatch.Length);
  86. 44
  87.  
  88. 45
  89. var symbol = ' ';
  90. 46
  91. if (leftMatch.Value[0] != rightMatch.Value[0])
  92. 47
  93. {
  94. 48
  95.  
  96. 49
  97. Console.WriteLine($"ticket \"{ticket}\" - no match");
  98. 50
  99. continue;
  100. 51
  101. }
  102. 52
  103. else
  104. 53
  105. {
  106. 54
  107. symbol = leftMatch.Value[0];
  108. 55
  109. }
  110. 56
  111.  
  112. 57
  113.  
  114. 58
  115.  
  116. 59
  117. if (counter == 10)
  118. 60
  119. {
  120. 61
  121. Console.WriteLine($"ticket \"{ ticket}\" - {counter}{symbol} Jackpot!");
  122. 62
  123. }
  124. 63
  125. else
  126. 64
  127. {
  128. 65
  129. Console.WriteLine($"ticket \"{ ticket}\" - {counter}{symbol}");
  130. 66
  131. }
  132. 67
  133. counter = 0;
  134. 68
  135. }
  136. 69
  137. else
  138. 70
  139. {
  140. 71
  141. Console.WriteLine($"ticket \"{ticket}\" - no match");
  142. 72
  143.  
  144. 73
  145. }
  146. 74
  147.  
  148. 75
  149.  
  150. 76
  151. }
  152. 77
  153. }
  154. 78
  155. }
  156. 79
  157. }
Advertisement
Add Comment
Please, Sign In to add comment