Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- 2
- using System.Collections.Generic;
- 3
- using System.Linq;
- 4
- using System.Text;
- 5
- using System.Text.RegularExpressions;
- 6
- using System.Threading.Tasks;
- 7
- 8
- namespace _04_WinningTicket
- 9
- {
- 10
- class Program
- 11
- {
- 12
- static void Main(string[] args)
- 13
- {
- 14
- var haveValidSimbols = "([$@#^])\\1{5,}";
- 15
- 16
- var tickets = Console.ReadLine()
- 17
- .Split(',')
- 18
- .Select(x => x.Trim())
- 19
- .ToArray();
- 20
- var leftPart = "";
- 21
- var rightPatr = "";
- 22
- 23
- Regex regex = new Regex(haveValidSimbols);
- 24
- 25
- foreach (var ticket in tickets)
- 26
- {
- 27
- 28
- if (ticket.Length != 20)
- 29
- {
- 30
- Console.WriteLine("invalid ticket");
- 31
- continue;
- 32
- }
- 33
- 34
- leftPart = ticket.Substring(0, ticket.Length / 2);
- 35
- rightPatr = ticket.Substring(ticket.Length / 2);
- 36
- 37
- var leftMatch = regex.Match(leftPart);
- 38
- var rightMatch = regex.Match(rightPatr);
- 39
- 40
- 41
- if (leftMatch.Success && rightMatch.Success)// && leftMatch == rightMatch)
- 42
- {
- 43
- var counter = Math.Min(leftMatch.Length, rightMatch.Length);
- 44
- 45
- var symbol = ' ';
- 46
- if (leftMatch.Value[0] != rightMatch.Value[0])
- 47
- {
- 48
- 49
- Console.WriteLine($"ticket \"{ticket}\" - no match");
- 50
- continue;
- 51
- }
- 52
- else
- 53
- {
- 54
- symbol = leftMatch.Value[0];
- 55
- }
- 56
- 57
- 58
- 59
- if (counter == 10)
- 60
- {
- 61
- Console.WriteLine($"ticket \"{ ticket}\" - {counter}{symbol} Jackpot!");
- 62
- }
- 63
- else
- 64
- {
- 65
- Console.WriteLine($"ticket \"{ ticket}\" - {counter}{symbol}");
- 66
- }
- 67
- counter = 0;
- 68
- }
- 69
- else
- 70
- {
- 71
- Console.WriteLine($"ticket \"{ticket}\" - no match");
- 72
- 73
- }
- 74
- 75
- 76
- }
- 77
- }
- 78
- }
- 79
- }
Advertisement
Add Comment
Please, Sign In to add comment