Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text.RegularExpressions;
- namespace _01._Winning_Ticket
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] collectionTickets = Console.ReadLine().Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
- string patternSpecialSymbols = @"(\${6,10})|(@{6,10})|(#{6,10})|(\^{6,10})";
- for (int i = 0; i < collectionTickets.Length; i++)
- {
- string ticket = collectionTickets[i];
- if (ticket.Length != 20)
- {
- Console.WriteLine("invalid ticket");
- }
- else if (ticket.Length == 20)
- {
- string rightSide = string.Empty;
- string leftSide = string.Empty;
- for (int j = 0; j < ticket.Length; j++)
- {
- if (j >= 0 && j < 10)
- {
- rightSide += ticket[j];
- }
- else if (j >= 10 && j < 20)
- {
- leftSide += ticket[j];
- }
- }
- MatchCollection matchesSpecialSymbolsRight = Regex.Matches(rightSide, patternSpecialSymbols);
- MatchCollection matchesSpecialSymbolsLeft = Regex.Matches(leftSide, patternSpecialSymbols);
- if (matchesSpecialSymbolsRight.Count != 1 && matchesSpecialSymbolsLeft.Count != 1)
- {
- Console.WriteLine($"ticket \"{ticket}\" - no match");
- }
- else if (matchesSpecialSymbolsRight.Count == 1 && matchesSpecialSymbolsLeft.Count == 1)
- {
- int lenght = Math.Min(matchesSpecialSymbolsRight[0].Length, matchesSpecialSymbolsLeft[0].Length);
- string stringSymbols = matchesSpecialSymbolsRight[0].ToString();
- char specialSymbol = stringSymbols[0];
- if (lenght == 10)
- {
- Console.WriteLine($"ticket \"{ticket}\" - {lenght}{specialSymbol} Jackpot!");
- }
- else
- {
- Console.WriteLine($"ticket \"{ticket}\" - {lenght}{specialSymbol}");
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment