1. Winning Ticket
Regular Expressions - More Exercise
Някой може ли да даде идея поради каква причина този код не работи в Judge?
using System.Text.RegularExpressions;
namespace StringPlay
{
internal class Program
{
static void Main()
{
string[] input = Console.ReadLine().Split(',', StringSplitOptions.TrimEntries);
Regex winningRegex = new Regex(@"(@{6,10}|#{6,10}|\${6,10})|\1");
foreach (var ticket in input)
{
if (ticket.Length != 20)
{
Console.WriteLine("invalid ticket");
continue;
}
MatchCollection matches = winningRegex.Matches(ticket);
if (matches.Count() == 0)
{
Console.WriteLine($"ticket \"{ticket}\" - no match");
continue;
}
else
{
int matchLength = 0;
if (matches[0].Value.Length > matches[1].Value.Length)
{
matchLength = matches[1].Value.Length;
}
else
{
matchLength = matches[0].Value.Length;
}
char matchSymbol = matches[0].Value[0];
if (matchLength >= 6 && matchLength <= 9)
{
Console.WriteLine($"ticket \"{ticket}\" - {matchLength}{matchSymbol}");
}
else if (matchLength > 9)
{
Console.WriteLine($"ticket \"{ticket}\" - {matchLength}{matchSymbol} Jackpot!");
}
}
}
}
}
}