Advertisement
Guest User

Untitled

a guest
Aug 11th, 2021
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace WinningTicket_MoreEx
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. string[] ticket = Console.ReadLine().Split(new char[] {',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
  11.  
  12. for (int i = 0; i < ticket.Length; i++)
  13. {
  14. if (ticket[i].Length == 20)
  15. {
  16. string winningPattern = @"[@\^$#]{6,}";
  17. string jackpotPattern = @"[@\^$#]{10}";
  18.  
  19. string firstHalf = "";
  20. string secondHalf = "";
  21.  
  22. for (int j = 0; j < ticket[i].Length; j++)
  23. {
  24. if (j < ticket[i].Length / 2)
  25. {
  26. firstHalf += ticket[i][j];
  27. }
  28. else
  29. {
  30. secondHalf += ticket[i][j];
  31. }
  32. }
  33.  
  34. Match jackpotFirstHalf = Regex.Match(firstHalf, jackpotPattern);
  35. Match jackpotSecondHalf = Regex.Match(secondHalf, jackpotPattern);
  36.  
  37. if (jackpotFirstHalf.Success && jackpotSecondHalf.Success)
  38. {
  39. Console.WriteLine($"ticket \"{ticket[i]}\" - {jackpotFirstHalf.Length}{jackpotFirstHalf.Value[0]} Jackpot!");
  40. }
  41. else
  42. {
  43. Match winFirstHalf = Regex.Match(firstHalf, winningPattern);
  44. Match winSecondHalf = Regex.Match(secondHalf, winningPattern);
  45.  
  46. if (winFirstHalf.Length >= 6 && winSecondHalf.Length >= 6 && winFirstHalf.Length == winSecondHalf.Length)
  47. {
  48. Console.WriteLine($"ticket \"{ticket[i]}\" - {winFirstHalf.Length}{winFirstHalf.Value[0]}");
  49. }
  50. else
  51. {
  52. Console.WriteLine($"ticket \"{ticket[i]}\" - no match");
  53. }
  54. }
  55. }
  56. else
  57. {
  58. Console.WriteLine("invalid ticket");
  59. }
  60. }
  61. }
  62. }
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement