using System; using System.Linq; namespace Miner { class Program { static void Main(string[] args) { int size = int.Parse(Console.ReadLine()); string[] commands = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); char[][] field = new char[size][]; int row = 0; int col = 0; int totalCoals = 0; int coalsFound = 0; bool isDead = false; bool hasWon = false; GetJaggedArray(size, field, ref row, ref col); GetTotalCoals(field, ref totalCoals); for (int i = 0; i < commands.Length; i++) { string direction = commands[i]; MoveMiner(field, direction, ref row, ref col,ref coalsFound, ref isDead); if(totalCoals == coalsFound) { hasWon = true; Console.WriteLine($"You collected all coals! ({row}, {col})"); break; } } if (isDead == false && hasWon==false) { Console.WriteLine($"{totalCoals - coalsFound} coals left. ({row}, {col})"); } } private static void GetTotalCoals(char[][] field,ref int totalCoals) { for (int i = 0; i < field.Length; i++) { for (int j = 0; j < field.Length; j++) { if(field[i][j]== 'c') { totalCoals++; } } } } private static void MoveMiner(char[][] field, string direction, ref int row, ref int col,ref int coalsFound,ref bool isDead) { switch (direction) { case "up": if (row - 1 >= 0) { field[row][col] = '*'; row--; if (field[row][col] == 'c') { coalsFound++; } else if (field[row][col] == 'e') { Console.WriteLine($"Game over! ({row}, {col})"); isDead = true; return; } field[row][col] = 's'; break; } else { break; } case "down": if (row + 1 < field.Length) { field[row][col] = '*'; row++; if (field[row][col] == 'c') { coalsFound++; } else if (field[row][col] == 'e') { Console.WriteLine($"Game over! ({row}, {col})"); isDead = true; return; } field[row][col] = 's'; break; } else { break; } case "left": if (col - 1 >= 0) { field[row][col] = '*'; col--; if (field[row][col] == 'c') { coalsFound++; } else if (field[row][col] == 'e') { Console.WriteLine($"Game over! ({row}, {col})"); isDead = true; return; } field[row][col] = 's'; break; } else { break; } case "right": if (col + 1 < field[row].Length) { field[row][col] = '*'; col++; if (field[row][col] == 'c') { coalsFound++; } else if (field[row][col] == 'e') { Console.WriteLine($"Game over! ({row}, {col})"); isDead = true; return; } field[row][col] = 's'; break; } else { break; } default: break; } } private static void GetJaggedArray(int size, char[][] field, ref int row, ref int col) { for (int i = 0; i < size; i++) { field[i] = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(char.Parse).ToArray(); if (field[i].Contains('s')) { row = i; col = Array.IndexOf(field[i], 's'); } } } } }