public int Left { get; set; }
public int Right { get; set; }
public static void Main()
"3-2,2-1,1-4,4-4,5-4,4-2,2-1",
"5-5,5-5,4-4,5-5,5-5,5-5,5-5,5-5,5-5,5-5",
"1-1,3-5,5-5,5-4,4-2,1-3",
"1-2,2-2,3-3,3-4,4-5,1-1,1-2"
for (int i = 0; i < S.Length; i++) {
public static void domino(string S)
int count = 0, max = 0, cur = -1;
if (!string.IsNullOrEmpty(S)) {
string[] split = S.Split(',');
for (int i = 0; i < split.Length; i++) {
string[] vals = split[i].Split('-');
throw new ArgumentException($"Invalid argument found: {split[i]}");
if (int.TryParse(vals[0], out left) && int.TryParse(vals[1], out right)) {
Domino d = new Domino { Left = left, Right = right };
if (cur == -1 || d.Left == cur) {
if (count > max) { max = count; }
throw new ArgumentException($"Invalid domino value: {split[i]}");
if (count > max) { max = count; }
Console.WriteLine($"Maximum domino chain in {S}: {max}");