krasi1105

04. Winning Ticket

Jan 24th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.71 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 _04.Winning_Ticket
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[] tickets = Console.ReadLine().Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
  14.             string[] outputs = new string[tickets.Length];
  15.             char[] winningSymbols = { '@', '$', '#', '^' };
  16.             for (int i = 0; i < tickets.Length; i++)
  17.             {
  18.                 string currentTicket = tickets[i];
  19.                 if (currentTicket.Length != 20)
  20.                 {
  21.                     outputs[i] = "invalid ticket";
  22.                 }
  23.                 else
  24.                 {
  25.                     char currentCharLeft = currentTicket[0];
  26.                     int timesInRowLeft = 0;
  27.                     bool winningLeft = false;
  28.                     for (int j = 0; j < 10; j++)
  29.                     {
  30.                         if (currentTicket[j] == currentCharLeft)
  31.                         {
  32.                             timesInRowLeft++;
  33.                         }
  34.                         else if(!winningLeft)
  35.                         {
  36.                             timesInRowLeft = 1;
  37.                             currentCharLeft = currentTicket[j];
  38.                         }
  39.  
  40.                         if (timesInRowLeft >= 6)
  41.                         {
  42.                             winningLeft = true;
  43.                         }
  44.                     }
  45.  
  46.                     if (winningLeft && winningSymbols.Contains(currentCharLeft))
  47.                     {
  48.                         char currentCharRight = currentTicket[19];
  49.                         int timesInRowRight = 0;
  50.                         bool winningRight = false;
  51.                         for (int j = 19; j >= 10; j--)
  52.                         {
  53.                             if (currentCharRight == currentTicket[j])
  54.                             {
  55.                                 timesInRowRight++;
  56.                             }
  57.                             else if (!winningRight)
  58.                             {
  59.                                 timesInRowRight = 1;
  60.                                 currentCharRight = currentTicket[j];
  61.                             }
  62.  
  63.                             if (timesInRowRight >= 6)
  64.                             {
  65.                                 winningRight = true;
  66.                             }
  67.                         }
  68.  
  69.                         if (winningRight && currentCharLeft == currentCharRight)
  70.                         {
  71.                             int lengthChars = timesInRowLeft > timesInRowRight ? timesInRowRight : timesInRowLeft;
  72.                             if (timesInRowRight == 10 && timesInRowLeft == 10)
  73.                             {
  74.                                 outputs[i] = $"ticket \"{currentTicket}\" - {lengthChars}{currentCharRight} Jackpot!";
  75.                             }
  76.                             else
  77.                             {
  78.                                 outputs[i] = $"ticket \"{currentTicket}\" - {lengthChars}{ currentCharRight}";
  79.                             }
  80.                         }
  81.                         else
  82.                         {
  83.                             outputs[i] = $"ticket \"{currentTicket}\" - no match";
  84.                         }
  85.                     }
  86.                     else
  87.                     {
  88.                         outputs[i] = $"ticket \"{currentTicket}\" - no match";
  89.                     }
  90.                 }
  91.             }
  92.  
  93.             foreach (string output in outputs)
  94.             {
  95.                 Console.WriteLine(output);
  96.             }
  97.         }
  98.     }
  99. }
Add Comment
Please, Sign In to add comment