Mike_Goodman92

Untitled

Oct 25th, 2017
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.74 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.  
  7. namespace startOverProb4
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string[] getTickets = Console.ReadLine().Split(new string[] { ", " }, StringSplitOptions.None);
  14.  
  15. foreach (var item in getTickets)
  16. {
  17. string trimmedItem = item.Trim();
  18.  
  19. if (trimmedItem.Length == 20)
  20. {
  21. string leftSide = trimmedItem.Substring(0 , 10);
  22. string rightSide = trimmedItem.Substring(10 , 10);
  23.  
  24. int conditionsForWinningLeft = FindAWinner(leftSide); // броят на печел. символи за лява страна
  25. int conditionsForWinningRight = FindAWinner(rightSide); // броят на печел. символи за дясна страна
  26.  
  27. string symbolLeft = getSymbol(leftSide); // какви са печел. символи от едната страна
  28. string symbolRight = getSymbol(rightSide); // -- /--
  29.  
  30. if (conditionsForWinningLeft == 0 || conditionsForWinningRight == 0 // ако няма печеливши символи на една от страните
  31. || symbolLeft != symbolRight // ако символите са различни
  32. || conditionsForWinningLeft != conditionsForWinningRight) // ако броят на печелившите символи от двете страни е различен
  33.  
  34. {
  35. Console.WriteLine($"ticket \"{leftSide}{rightSide}\" - no match");
  36. continue;
  37. }
  38.  
  39. if (conditionsForWinningLeft == conditionsForWinningRight && symbolLeft == symbolRight)
  40. {
  41. switch (conditionsForWinningLeft)
  42. {
  43. case 6: Console.WriteLine($"ticket \"{leftSide}{rightSide}\" - {conditionsForWinningLeft}{symbolLeft}"); break;
  44. case 7: Console.WriteLine($"ticket \"{leftSide}{rightSide}\" - {conditionsForWinningLeft}{symbolLeft}"); break;
  45. case 8: Console.WriteLine($"ticket \"{leftSide}{rightSide}\" - {conditionsForWinningLeft}{symbolLeft}"); break;
  46. case 9: Console.WriteLine($"ticket \"{leftSide}{rightSide}\" - {conditionsForWinningLeft}{symbolLeft}"); break;
  47. case 10: Console.WriteLine($"ticket \"{leftSide}{rightSide}\" - {conditionsForWinningLeft}{symbolLeft} Jackpot!"); break;
  48. }
  49.  
  50. }
  51.  
  52. }
  53. else
  54. {
  55. Console.WriteLine("invalid ticket");
  56. }
  57.  
  58.  
  59. }
  60.  
  61. }
  62.  
  63. private static string getSymbol(string side)
  64. {
  65. string symbol = "no luck";
  66.  
  67. bool one = side.Contains(new string('@', 6));
  68. bool two = side.Contains(new string('#', 6));
  69. bool three = side.Contains(new string('$', 6));
  70. bool four = side.Contains(new string('^', 6));
  71.  
  72. if (one)
  73. {
  74. symbol = "@";
  75. }
  76.  
  77. if (two)
  78. {
  79. symbol = "#";
  80. }
  81.  
  82. if (three)
  83. {
  84. symbol = "$";
  85. }
  86.  
  87. if (four)
  88. {
  89. symbol = "^";
  90. }
  91.  
  92. return symbol;
  93. }
  94.  
  95.  
  96. private static int FindAWinner(string side)
  97. {
  98. int count = 0;
  99.  
  100. bool one = side.Contains(new string('@', 6));
  101. bool two = side.Contains(new string('#', 6));
  102. bool three = side.Contains(new string('$', 6));
  103. bool four = side.Contains(new string('^', 6));
  104.  
  105. if (one || two || three || four)
  106. {
  107. count = 6;
  108. }
  109.  
  110. bool one1 = side.Contains(new string('@', 7));
  111. bool two1 = side.Contains(new string('#', 7));
  112. bool three1 = side.Contains(new string('$', 7));
  113. bool four1 = side.Contains(new string('^', 7));
  114.  
  115. if (one1 || two1 || three1 || four1)
  116. {
  117. count = 7;
  118. }
  119.  
  120. bool one2 = side.Contains(new string('@', 8));
  121. bool two2 = side.Contains(new string('#', 8));
  122. bool three2 = side.Contains(new string('$', 8));
  123. bool four2 = side.Contains(new string('^', 8));
  124.  
  125. if (one2 || two2 || three2 || four2)
  126. {
  127. count = 8;
  128. }
  129.  
  130. bool one3 = side.Contains(new string('@', 9));
  131. bool two3 = side.Contains(new string('#', 9));
  132. bool three3 = side.Contains(new string('$', 9));
  133. bool four3 = side.Contains(new string('^', 9));
  134.  
  135. if (one3 || two3 || three3 || four3)
  136. {
  137. count = 9;
  138. }
  139.  
  140. bool jackone = side.Contains(new string('@', 10));
  141. bool jacktwo = side.Contains(new string('#', 10));
  142. bool jackthree = side.Contains(new string('$', 10));
  143. bool jackfour = side.Contains(new string('^', 10));
  144.  
  145. if (jackone || jacktwo || jackthree || jackfour)
  146. {
  147. count = 10;
  148. }
  149.  
  150. return count;
  151. }
  152.  
  153. }
  154. }
Add Comment
Please, Sign In to add comment