sivancheva

WinningTicket

Oct 30th, 2017
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text.RegularExpressions;
  4.  
  5.  
  6. namespace _04_WinningTicket
  7. {
  8. class WinningTicket
  9. {
  10. static void Main(string[] args)
  11. {
  12. var input = Console.ReadLine().Split(',').Select(x => x.Trim()).ToArray();
  13.  
  14.  
  15. for (int i = 0; i < input.Length; i++)
  16. {
  17.  
  18. if (input[i].Length != 20)
  19. {
  20. Console.WriteLine("invalid ticket");
  21. continue;
  22. }
  23.  
  24. else if (input[i].Length == 20)
  25. {
  26. Regex r = new Regex($@"^[$]{{{20}}}|[@]{{{20}}}|[#]{{{20}}}|[\^]{{{20}}}$");
  27. bool containsAny = r.IsMatch(input[i]);
  28. if (containsAny)
  29. {
  30. Console.WriteLine($"ticket \"{input[i]}\" - 10{input[i][0]} Jackpot!");
  31. continue;
  32. }
  33.  
  34. string firstHalf = input[i].Substring(0, 10);
  35. string secondHalf = input[i].Substring(10, 10);
  36.  
  37. //Regex r2 = new Regex($@"^[$]{{{6,10}}}|[@]{{{6,10}}}|[#]{{{6,10}}}|[\^]{{{6,10}}}$"); //gre6en RegEx
  38. Regex r2 = new Regex(@"[@]{6,10}|[#]{6,10}|[$]{6,10}|[\^]{6,10}"); //pravilen Regex
  39.  
  40. bool firstHalfMatch = r2.IsMatch(firstHalf);
  41. bool secondfMatch = r2.IsMatch(secondHalf);
  42.  
  43.  
  44. if (!firstHalfMatch || !secondfMatch)
  45. {
  46. Console.WriteLine($"ticket \"{input[i]}\" - no match");
  47. continue;
  48. }
  49. var firstHalfMatchString = r2.Match(firstHalf).ToString(); //
  50. var secondHalfMatchString = r2.Match(secondHalf).ToString(); //
  51.  
  52.  
  53. if (firstHalfMatchString[0] != secondHalfMatchString[0])
  54. {
  55. Console.WriteLine($"ticket \"{input[i]}\" - no match");
  56. continue;
  57. }
  58. else if (firstHalfMatchString[0] == secondHalfMatchString[0])
  59. {
  60. Console.WriteLine($"ticket \"{input[i]}\" - {Math.Min(firstHalfMatchString.Length, secondHalfMatchString.Length)}{firstHalfMatchString[0]}");
  61. continue;
  62. }
  63. }
  64. }
  65. }
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment