anizko

1. Winning Ticket 80/100

Jul 26th, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.53 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace _01._Winning_Ticket
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string[] collectionTickets = Console.ReadLine().Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
  11.             string patternSpecialSymbols = @"(\${6,10})|(@{6,10})|(#{6,10})|(\^{6,10})";
  12.  
  13.             for (int i = 0; i < collectionTickets.Length; i++)
  14.             {
  15.                 string ticket = collectionTickets[i];
  16.  
  17.                 if (ticket.Length != 20)
  18.                 {
  19.                     Console.WriteLine("invalid ticket");
  20.                 }
  21.                 else if (ticket.Length == 20)
  22.                 {
  23.                     string rightSide = string.Empty;
  24.                     string leftSide = string.Empty;
  25.                     for (int j = 0; j < ticket.Length; j++)
  26.                     {
  27.                         if (j >= 0 && j < 10)
  28.                         {
  29.                             rightSide += ticket[j];
  30.                         }
  31.                         else if (j >= 10 && j < 20)
  32.                         {
  33.                             leftSide += ticket[j];
  34.                         }
  35.                     }
  36.  
  37.                     MatchCollection matchesSpecialSymbolsRight = Regex.Matches(rightSide, patternSpecialSymbols);
  38.                     MatchCollection matchesSpecialSymbolsLeft = Regex.Matches(leftSide, patternSpecialSymbols);
  39.  
  40.                     if (matchesSpecialSymbolsRight.Count != 1 && matchesSpecialSymbolsLeft.Count != 1)
  41.                     {
  42.                         Console.WriteLine($"ticket \"{ticket}\" - no match");
  43.                     }
  44.                     else if (matchesSpecialSymbolsRight.Count == 1 && matchesSpecialSymbolsLeft.Count == 1)
  45.                     {
  46.                         int lenght = Math.Min(matchesSpecialSymbolsRight[0].Length, matchesSpecialSymbolsLeft[0].Length);
  47.                         string stringSymbols = matchesSpecialSymbolsRight[0].ToString();
  48.                         char specialSymbol = stringSymbols[0];
  49.  
  50.                         if (lenght == 10)
  51.                         {
  52.                             Console.WriteLine($"ticket \"{ticket}\" - {lenght}{specialSymbol} Jackpot!");
  53.                         }
  54.                         else
  55.                         {
  56.                             Console.WriteLine($"ticket \"{ticket}\" - {lenght}{specialSymbol}");
  57.                         }
  58.                     }
  59.                 }
  60.             }
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment