Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace WinningTicket
- {
- public class WinningTicket
- {
- public static void Main()
- {
- string[] allTickets = Console.ReadLine().Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
- Regex winningTicket = new Regex(@"([$]{6,}|[@]{6,}|[\^]{6,}|[#]{6,})");
- Regex jackpotTicket = new Regex(@"([$]{20}|[@]{20}|[\^]{20}|[#]{20})");
- string[] result = new string[allTickets.Length];
- for (int currTicket = 0; currTicket < allTickets.Length; currTicket++)
- {
- string ticket = allTickets[currTicket];
- if (ticket.Length != 20)
- {
- result[currTicket] = "invalid ticket";
- continue;
- }
- if (jackpotTicket.IsMatch(ticket))
- {
- result[currTicket] = $"ticket \"{ticket}\" - 10{ticket[0]} Jackpot!";
- continue;
- }
- string leftHalf = ticket.Substring(0, 10);
- string rightHalf = ticket.Substring(10, 10);
- if (!winningTicket.IsMatch(leftHalf))
- {
- result[currTicket] = $"ticket \"{ticket}\" - no match";
- continue;
- }
- Match leftMatch = winningTicket.Match(leftHalf);
- Match rightMatch = winningTicket.Match(rightHalf);
- leftHalf = leftMatch.Groups[1].ToString();
- rightHalf = rightMatch.Groups[1].ToString();
- if (leftHalf == rightHalf)
- {
- result[currTicket] = $"ticket \"{ticket}\" - {leftHalf.Length}{leftHalf[0]}";
- }
- }
- for (int currTicket = 0; currTicket < result.Length; currTicket++)
- {
- Console.WriteLine(result[currTicket]);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment