Advertisement
Guest User

Untitled

a guest
Jun 17th, 2018
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Text.RegularExpressions;
  7.  
  8. namespace _04.WinningTicket
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. string[] tickets = Console.ReadLine().Split(new[] { ',', ' ' },
  15. StringSplitOptions.RemoveEmptyEntries).
  16. Select(x => x.Trim()).ToArray();
  17.  
  18. foreach (var ticket in tickets)
  19. {
  20. if (ticket.Length == 20)
  21. {
  22. string leftHalf = string.Join("", ticket.Take(10).ToArray());
  23. string rightHalf = string.Join("", ticket.Skip(10).Take(10).ToArray());
  24.  
  25. string pattern = @"([@|#|$|^])\1{5,9}";
  26. if (Regex.IsMatch(leftHalf, pattern))
  27. {
  28. Match repeatLeft = Regex.Match(leftHalf, pattern);
  29. string symbolsLeft = repeatLeft.Value;
  30. char charLeft = symbolsLeft[0];
  31. int lenghtLeft = repeatLeft.Value.Count();
  32.  
  33. Match repeatRight = Regex.Match(rightHalf, pattern);
  34. string symbolsRight = repeatRight.Value;
  35. char charRight = symbolsRight[0];
  36. int lenghtRight = repeatRight.Value.Count();
  37.  
  38. int minLenght = Math.Min(lenghtLeft, lenghtRight);
  39.  
  40. if (minLenght >= 6 && charLeft == charRight)
  41. {
  42. if (lenghtRight == 10)
  43. {
  44. Console.WriteLine($"ticket \"{ ticket}\" - {minLenght}{charRight} Jackpot!");
  45. }
  46. else
  47. {
  48. Console.WriteLine($"ticket \"{ ticket}\" - {minLenght}{charRight}");
  49. }
  50. }
  51. else
  52. {
  53. // that in case whene left and right symbols are difrent or haven't right symbols
  54. Console.WriteLine($"ticket \"{ticket}\" - no match");
  55. }
  56. }
  57. else
  58. {
  59. Console.WriteLine($"ticket \"{ticket}\" - no match");
  60. }
  61. }
  62. else
  63. {
  64. Console.WriteLine("invalid ticket");
  65. }
  66. }
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement