Advertisement
Guest User

Untitled

a guest
Aug 11th, 2021
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 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. string winningPattern = @"[$]{6,}|[$]{6,}|[@]{6}|[\^]{6,}|[#]{6,}";
  19. string jackpotPattern = @"[$]{10}|[$]{10}|[@]{10}|[\^]{10}|[#]{10}";
  20.  
  21. string firstHalf = "";
  22. string secondHalf = "";
  23.  
  24. for (int j = 0; j < ticket[i].Length; j++)
  25. {
  26. if (j < ticket[i].Length / 2)
  27. {
  28. firstHalf += ticket[i][j];
  29. }
  30. else
  31. {
  32. secondHalf += ticket[i][j];
  33. }
  34. }
  35.  
  36. Match jackpotFirstHalf = Regex.Match(firstHalf, jackpotPattern);
  37. Match jackpotSecondHalf = Regex.Match(secondHalf, jackpotPattern);
  38.  
  39. if (jackpotFirstHalf.Success && jackpotSecondHalf.Success)
  40. {
  41. Console.WriteLine($"ticket \"{ticket[i]}\" - {jackpotFirstHalf.Length}{jackpotFirstHalf.Value[0]} Jackpot!");
  42. }
  43. else
  44. {
  45. Match winFirstHalf = Regex.Match(firstHalf, winningPattern);
  46. Match winSecondHalf = Regex.Match(secondHalf, winningPattern);
  47.  
  48. if (winFirstHalf.Length >= 6 && winSecondHalf.Length >= 6 && winFirstHalf.Length == winSecondHalf.Length)
  49. {
  50. Console.WriteLine($"ticket \"{ticket[i]}\" - {winFirstHalf.Length}{winFirstHalf.Value[0]}");
  51. }
  52. else
  53. {
  54. Console.WriteLine($"ticket \"{ticket[i]}\" - no match");
  55. }
  56. }
  57. }
  58. else
  59. {
  60. Console.WriteLine("invalid ticket");
  61. }
  62. }
  63. }
  64. }
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement