Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace judgeMatrix
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] size = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
- int rowsInput = size[0];
- int colsInput = size[1];
- int[,] matrix = new int[rowsInput,colsInput];
- int currentRow = 0;
- int currentCol = 0;
- int money = 0;
- int left = 0;
- int right = 0;
- int down = 0;
- int up = 0;
- for (int rows = 0; rows < rowsInput; rows++)
- {
- int[] input = new int[colsInput];
- input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
- for (int cols = 0; cols < colsInput; cols++)
- {
- matrix[rows, cols] = input[cols];
- if (matrix[rows,cols] == 0)
- {
- currentRow = rows;
- currentCol = cols;
- }
- }
- }
- //MatrinPrint(rowsInput,colsInput,matrix);
- while (true)
- {
- if (currentRow != 0)
- {
- up = matrix[currentRow - 1, currentCol];
- }
- else
- {
- up = 0;
- }
- if (currentRow != rowsInput-1)
- {
- down = matrix[currentRow + 1, currentCol];
- }
- else
- {
- down = 0;
- }
- if (currentCol != 0 )
- {
- left = matrix[currentRow, currentCol - 1];
- }
- else
- {
- left = 0;
- }
- if (currentCol != colsInput -1)
- {
- right = matrix[currentRow, currentCol +1];
- }
- else
- {
- right = 0;
- }
- if (right == 0 && left==0 && up == 0 && down ==0)
- {
- break;
- }
- if (left >= right && left >= up && left >= down)
- {
- currentCol = currentCol - 1;
- matrix[currentRow, currentCol] = matrix[currentRow, currentCol] - 1;
- money++;
- }
- else if (right >= up && right >= down)
- {
- currentCol = currentCol + 1;
- matrix[currentRow, currentCol] = matrix[currentRow, currentCol] - 1;
- money++;
- }
- else if (up >=down)
- {
- currentRow = currentRow - 1;
- matrix[currentRow, currentCol] = matrix[currentRow, currentCol] - 1;
- money++;
- }
- else
- {
- currentRow = currentRow + 1;
- matrix[currentRow, currentCol] = matrix[currentRow, currentCol] - 1;
- money++;
- }
- /*
- if (right == left && right == down && right == up)
- {
- currentCol = currentCol - 1;
- matrix[currentRow, currentCol] = matrix[currentRow, currentCol] - 1;
- money++;
- }
- if (left == up && left == down)
- {
- currentCol = currentCol + 1;
- matrix[currentRow, currentCol] = matrix[currentRow, currentCol] - 1;
- money++;
- }
- if (up == down)
- {
- currentRow = currentRow - 1;
- matrix[currentRow, currentCol] = matrix[currentRow, currentCol] - 1;
- money++;
- }
- if (up > down && left > right)
- {
- currentRow = currentRow - 1;
- currentCol = currentCol - 1;
- matrix[currentRow, currentCol] = matrix[currentRow, currentCol] - 1;
- money++;
- }
- if (up > down && left < right)
- {
- currentRow = currentRow - 1;
- currentCol = currentCol + 1;
- matrix[currentRow, currentCol] = matrix[currentRow, currentCol] - 1;
- money++;
- }
- if (up < down && left > right)
- {
- currentRow = currentRow + 1;
- currentCol = currentCol - 1;
- matrix[currentRow, currentCol] = matrix[currentRow, currentCol] - 1;
- money++;
- }
- if (up < down && left < right)
- {
- currentRow = currentRow + 1;
- currentCol = currentCol + 1;
- matrix[currentRow, currentCol] = matrix[currentRow, currentCol] - 1;
- money++;
- }
- */
- }
- Console.WriteLine(money);
- }
- private static void MatrinPrint(int lenOfRows, int lenOfCols, int[,] matrix)
- {
- for (int rows = 0; rows < lenOfRows; rows++)
- {
- for (int cols = 0; cols < lenOfCols; cols++)
- {
- Console.Write(matrix[rows,cols]+ " ");
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement