Advertisement
ghostd0g

Untitled

Feb 27th, 2018
1,296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.25 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Exercise4
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string[] tickets = Console.ReadLine().Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
  15.             string[] winningSymbols = new string[] { "@", "#", "$", @"\^" };
  16.  
  17.             for (int i = 0; i < tickets.Length; i++)
  18.             {
  19.                 if (tickets[i].Length != 20)
  20.                 {
  21.                     Console.WriteLine("invalid ticket");
  22.                     continue;
  23.                 }
  24.  
  25.                 bool noMatch = false;
  26.  
  27.                 for (int b = 0; b < winningSymbols.Length; b++)
  28.                 {
  29.                     string currentPattern = $@"[{winningSymbols[b]}]+";
  30.  
  31.                     string leftSideOfTicket = tickets[i].Substring(0,10);
  32.                     string rightSideOfTicket = tickets[i].Substring(10, 10);
  33.  
  34.                     int counterLeft = 0;
  35.                     int counterRight = 0;
  36.  
  37.  
  38.                     foreach (Match match in Regex.Matches(leftSideOfTicket, currentPattern))
  39.                     {
  40.                         counterLeft = match.Value.Length;
  41.                     }
  42.                     foreach (Match match in Regex.Matches(rightSideOfTicket, currentPattern))
  43.                     {
  44.                         counterRight = match.Value.Length;
  45.                     }
  46.  
  47.                     if (counterLeft >= 6 && counterRight >= 6 && (counterLeft + counterRight) < 20)
  48.                     {
  49.  
  50.                         if (winningSymbols[b] == @"\^")
  51.                         {
  52.                             Console.WriteLine("ticket \"" + tickets[i] + "\" - " + Math.Min(counterLeft, counterRight) + "^");
  53.                         }
  54.                         else
  55.                         {
  56.                             Console.WriteLine("ticket \"" + tickets[i] + "\" - " + Math.Min(counterLeft, counterRight) + "" + winningSymbols[b]);
  57.                         }                      
  58.                         noMatch = true;
  59.                         break;
  60.                     }
  61.                     else if ((counterLeft + counterRight) == 20)
  62.                     {
  63.                         if (winningSymbols[b] == @"\^")
  64.                         {
  65.                             Console.WriteLine("ticket \"" + tickets[i] + "\" - " + Math.Min(counterLeft, counterRight) + "^ Jackpot!");
  66.                         }
  67.                         else
  68.                         {
  69.                             Console.WriteLine("ticket \"" + tickets[i] + "\" - " + Math.Min(counterLeft, counterRight) + "" + winningSymbols[b] + " Jackpot!");
  70.                         }                        
  71.                         noMatch = true;
  72.                         break;
  73.                     }
  74.                     else
  75.                     {
  76.                         noMatch = false;
  77.                        
  78.                     }
  79.                 }
  80.  
  81.                 if (noMatch == false)
  82.                 {
  83.                     Console.WriteLine("ticket \"" + tickets[i] + "\" - no match");
  84.                 }
  85.             }
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement