Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text.RegularExpressions;
- namespace WinningTicket_MoreEx
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] ticket = Console.ReadLine().Split(new char[] {',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
- for (int i = 0; i < ticket.Length; i++)
- {
- if (ticket[i].Length == 20)
- {
- string winningPattern = @"[@\^$#]{6,}";
- string jackpotPattern = @"[@\^$#]{10}";
- string firstHalf = "";
- string secondHalf = "";
- for (int j = 0; j < ticket[i].Length; j++)
- {
- if (j < ticket[i].Length / 2)
- {
- firstHalf += ticket[i][j];
- }
- else
- {
- secondHalf += ticket[i][j];
- }
- }
- Match jackpotFirstHalf = Regex.Match(firstHalf, jackpotPattern);
- Match jackpotSecondHalf = Regex.Match(secondHalf, jackpotPattern);
- if (jackpotFirstHalf.Success && jackpotSecondHalf.Success)
- {
- Console.WriteLine($"ticket \"{ticket[i]}\" - {jackpotFirstHalf.Length}{jackpotFirstHalf.Value[0]} Jackpot!");
- }
- else
- {
- Match winFirstHalf = Regex.Match(firstHalf, winningPattern);
- Match winSecondHalf = Regex.Match(secondHalf, winningPattern);
- if (winFirstHalf.Length >= 6 && winSecondHalf.Length >= 6 && winFirstHalf.Length == winSecondHalf.Length)
- {
- Console.WriteLine($"ticket \"{ticket[i]}\" - {winFirstHalf.Length}{winFirstHalf.Value[0]}");
- }
- else
- {
- Console.WriteLine($"ticket \"{ticket[i]}\" - no match");
- }
- }
- }
- else
- {
- Console.WriteLine("invalid ticket");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement