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;
- }
- MatchCollection allMatches = winningTicket.Matches(ticket);
- List<string> matches = new List<string>();
- foreach (Match currMatch in allMatches)
- {
- matches.Add(currMatch.Groups[1].ToString());
- }
- bool thereIsMatch = false;
- for (int currMatch = 0; currMatch < matches.Count; currMatch++)
- {
- for (int currCheck = currMatch + 1; currCheck < matches.Count; currCheck++)
- {
- if (matches[currMatch] == matches[currCheck])
- {
- thereIsMatch = true;
- break;
- }
- }
- if (thereIsMatch)
- {
- result[currTicket] = $"ticket \"{ticket}\" - {matches[currMatch].Length}{matches[currMatch][0]}";
- break;
- }
- }
- if (!thereIsMatch)
- {
- result[currTicket] = $"ticket \"{ticket}\" - no match";
- }
- }
- for (int currTicket = 0; currTicket < result.Length; currTicket++)
- {
- Console.WriteLine(result[currTicket]);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment