Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace _04_Winning_Ticket
- {
- public class WinningTicket
- {
- public static void Main()
- {
- var tickets = Console.ReadLine().Split(", ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToArray();
- foreach (var ticket in tickets)
- {
- if (ticket.Length != 20)
- {
- Console.WriteLine("invalid ticket");
- }
- else
- {
- var leftSide = new string(ticket.Take(10).ToArray());
- var rightSide = new string(ticket.Skip(10).Take(10).ToArray());
- var leftSeq = SideSeqCount(leftSide);
- var rightSeq = SideSeqCount(rightSide);
- var outputChar = SideCharCount(leftSide);
- int repeatedSeq = Math.Min(leftSeq, rightSeq);
- if (repeatedSeq == 10)
- {
- Console.WriteLine($"ticket \"{ticket}\" - {repeatedSeq}{outputChar} Jackpot!");
- }
- else if (repeatedSeq >= 6 && repeatedSeq <= 9)
- {
- Console.WriteLine($"ticket \"{ticket}\" - {repeatedSeq}{outputChar}");
- }
- else
- {
- Console.WriteLine($"ticket \"{ticket}\" - no match");
- }
- }
- }
- }
- static char SideCharCount(string side)
- {
- int cnt = 1;
- int bestCnt = int.MinValue;
- char currChar = char.MinValue;
- char bestChar = char.MinValue;
- for (int i = 0; i < side.Length - 1; i++)
- {
- char current = side[i];
- char next = side[i + 1];
- if (current == '#' || current == '@' || current == '$' || current == '^')
- {
- if (current == next)
- {
- cnt++;
- currChar = side[i];
- }
- else
- {
- if (cnt > bestCnt)
- {
- bestCnt = cnt;
- bestChar = currChar;
- cnt = 1;
- }
- }
- }
- }
- if (cnt > bestCnt)
- {
- bestCnt = cnt;
- bestChar = currChar;
- cnt = 1;
- }
- return bestChar;
- }
- static int SideSeqCount(string side)
- {
- int cnt = 1;
- int bestCnt = int.MinValue;
- for (int i = 0; i < side.Length - 1; i++)
- {
- char current = side[i];
- char next = side[i + 1];
- if (current == '#' || current == '@' || current == '$' || current == '^')
- {
- if (current == next)
- {
- cnt++;
- }
- else
- {
- if (cnt > bestCnt)
- {
- bestCnt = cnt;
- cnt = 1;
- }
- }
- }
- }
- if (cnt > bestCnt)
- {
- bestCnt = cnt;
- cnt = 1;
- }
- return bestCnt;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement