Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Text.RegularExpressions;
- namespace _04.WinningTicket
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] tickets = Console.ReadLine().Split(new[] { ',', ' ' },
- StringSplitOptions.RemoveEmptyEntries).
- Select(x => x.Trim()).ToArray();
- foreach (var ticket in tickets)
- {
- if (ticket.Length == 20)
- {
- string leftHalf = string.Join("", ticket.Take(10).ToArray());
- string rightHalf = string.Join("", ticket.Skip(10).Take(10).ToArray());
- string pattern = @"([@|#|$|^])\1{5,9}";
- if (Regex.IsMatch(leftHalf, pattern))
- {
- Match repeatLeft = Regex.Match(leftHalf, pattern);
- string symbolsLeft = repeatLeft.Value;
- char charLeft = symbolsLeft[0];
- int lenghtLeft = repeatLeft.Value.Count();
- Match repeatRight = Regex.Match(rightHalf, pattern);
- string symbolsRight = repeatRight.Value;
- char charRight = symbolsRight[0];
- int lenghtRight = repeatRight.Value.Count();
- int minLenght = Math.Min(lenghtLeft, lenghtRight);
- if (minLenght >= 6 && charLeft == charRight)
- {
- if (lenghtRight == 10)
- {
- Console.WriteLine($"ticket \"{ ticket}\" - {minLenght}{charRight} Jackpot!");
- }
- else
- {
- Console.WriteLine($"ticket \"{ ticket}\" - {minLenght}{charRight}");
- }
- }
- else
- {
- // that in case whene left and right symbols are difrent or haven't right symbols
- Console.WriteLine($"ticket \"{ticket}\" - no match");
- }
- }
- else
- {
- Console.WriteLine($"ticket \"{ticket}\" - no match");
- }
- }
- else
- {
- Console.WriteLine("invalid ticket");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement