Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main(string[] args)
- {
- int[,] matrix = new int[5, 7];
- int maxRowLength = matrix.GetLength(0);
- int maxColLength = matrix.GetLength(1);
- int row = 2;
- int col = 3;
- while (command != "end")
- {
- int stepRow = 0;
- int stepCol = 0;
- switch (command)
- {
- case "left":
- stepCol--;
- break;
- case "right":
- stepCol++;
- break;
- case "up":
- stepRow--;
- break;
- case "down":
- stepRow++;
- break;
- default:
- break;
- }
- int newRow = row + stepRow;
- int newCol = col + stepCol;
- if (IsNewPositionValid(maxRowLength, maxColLength, newRow, newCol))
- {
- // TODO: Изпълнение логиката на задачата
- row = newRow;
- col = newCol;
- }
- }
- }
- private static bool IsNewPositionValid(int maxRowLength, int maxColLength, int newRow, int newCol)
- {
- bool result = ((newRow >= 0) && (newRow < maxRowLength));
- result = ((result) && (newCol >= 0) && (newCol < maxColLength));
- return result;
- }
Advertisement
RAW Paste Data
Copied
Advertisement