Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace miner
- {
- class miner
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- var command = Console.ReadLine().Split();
- var matrix = new char[n, n];
- int currentRow = 0;
- int currentCol = 0;
- for (int i = 0; i < n; i++)
- {
- var lines = Console.ReadLine().ToCharArray();
- for (int j = 0; j < n; j++)
- {
- matrix[i, j] = lines[j];
- }
- }
- int coalCounter = 0;
- for (int row = 0; row < n; row++)
- {
- for (int col = 0; col < n; col++)
- {
- if (matrix[row, col] == 's')
- {
- for (int i = 0; i < command.Length; i++)
- {
- if (command[i] == "up")
- {
- if (row - 1 >= 0)
- {
- currentRow = row - 1;
- currentCol = col;
- if (matrix[currentRow, currentCol] == 'c')
- {
- coalCounter++;
- matrix[currentRow, currentCol] = '*';
- }
- else if (matrix[currentRow, currentCol] == 'e')
- {
- Console.WriteLine($"Game over! ({currentRow}, {currentCol})");
- return;
- }
- row = row - 1;
- }
- }
- else if (command[i] == "down")
- {
- if (row + 1 < matrix.GetLength(0))
- {
- currentRow = row + 1;
- currentCol = col;
- if (matrix[currentRow, currentCol] == 'c')
- {
- coalCounter++;
- matrix[currentRow, currentCol] = '*';
- }
- else if (matrix[currentRow, currentCol] == 'e')
- {
- Console.WriteLine($"Game over! ({currentRow}, {currentCol})");
- return;
- }
- row = row + 1;
- }
- }
- else if (command[i] == "right")
- {
- if (col + 1 < matrix.GetLength(1))
- {
- currentRow = row;
- currentCol = col + 1;
- if (matrix[currentRow, currentCol] == 'c')
- {
- coalCounter++;
- matrix[currentRow, currentCol] = '*';
- }
- else if (matrix[currentRow, currentCol] == 'e')
- {
- Console.WriteLine($"Game over! ({currentRow}, {currentCol})");
- return;
- }
- col = col + 1;
- }
- }
- else if (command[i] == "left")
- {
- if (col - 1 >= 0)
- {
- currentRow = row;
- currentCol = col - 1;
- if (matrix[currentRow, currentCol] == 'c')
- {
- coalCounter++;
- matrix[currentRow, currentCol] = '*';
- }
- else if (matrix[currentRow, currentCol] == 'e')
- {
- Console.WriteLine($"Game over! ({currentRow}, {currentCol})");
- return;
- }
- col = col - 1;
- }
- }
- int ccounter = 0;
- foreach (var item in matrix)
- {
- if (item == 'c')
- {
- ccounter++;
- }
- }
- if (ccounter == 0)
- {
- Console.WriteLine($"You collected all coals! ({row}, {col})");
- return;
- }
- if (i == command.Length - 1)
- {
- int cnt = 0;
- foreach (var item in matrix)
- {
- if (item == 'c')
- {
- cnt++;
- }
- }
- Console.WriteLine($"{cnt} coals left. ({row}, {col})");
- return;
- }
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement