Advertisement
Guest User

Untitled

a guest
Mar 19th, 2020
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7. namespace Winning_Ticket
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string[] input = Console.ReadLine().Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
  14.  
  15. string pattern = @"[$]{6,}|[@]{6,}|[#]{6,}|[\^]{6,}";
  16. string allSymbolsLeft = String.Empty;
  17. string allSymboRight = String.Empty;
  18. string singleSymbolLeft = String.Empty;
  19. string singleSymbolRight = String.Empty;
  20. string leftSide = String.Empty;
  21. string rightSide = String.Empty;
  22. for (int i = 0; i < input.Length; i++)
  23. {
  24. string currentTicket = input[i];
  25.  
  26. if (currentTicket.Length != 20)
  27. {
  28. Console.WriteLine("invalid ticket");
  29. }
  30. else if (currentTicket.Length == 20)
  31. {
  32. leftSide = currentTicket.Substring(0,10);
  33. rightSide = currentTicket.Substring(10,10);
  34.  
  35. Regex regex = new Regex(pattern);
  36. var matchesLeftSide = regex.Match(leftSide);
  37. var matchesRightSide = regex.Match(rightSide);
  38.  
  39. int lenLeftSide = matchesLeftSide.Length;
  40. int lenRightSide = matchesRightSide.Length;
  41.  
  42. allSymbolsLeft = matchesLeftSide.ToString();
  43. allSymboRight = matchesRightSide.ToString();
  44.  
  45. if (lenLeftSide >= 6 && lenRightSide >= 6)
  46. {
  47. singleSymbolLeft = allSymbolsLeft[0].ToString();
  48. singleSymbolRight = allSymboRight[0].ToString();
  49. }
  50.  
  51.  
  52. if (lenLeftSide >= 6 && lenRightSide >= 6 && lenLeftSide == lenRightSide && singleSymbolLeft == singleSymbolRight )
  53. {
  54. if (lenRightSide == 10 && lenLeftSide == 10)
  55. {
  56. Console.WriteLine($"ticket \"{currentTicket}\" - {lenRightSide}{singleSymbolRight} Jackpot!");
  57. }
  58. else if (lenRightSide >= 6 && lenRightSide <= 9)
  59. {
  60. Console.WriteLine($"ticket \"{currentTicket}\" - {lenRightSide}{singleSymbolRight}");
  61. }
  62.  
  63.  
  64. }
  65. else
  66. {
  67. Console.WriteLine($"ticket \"{currentTicket}\" - no match");
  68. }
  69. }
  70.  
  71. }
  72.  
  73. //Console.WriteLine(leftSide);
  74. //Console.WriteLine(rightSide);
  75. }
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement