Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- class KnightPath
- {
- static void Main()
- {
- string direction = Console.ReadLine();
- var allDirections = new List<string>();
- allDirections.Add(direction);
- while (true)
- {
- direction = Console.ReadLine();
- if (direction == "stop")
- {
- break;
- }
- allDirections.Add(direction);
- }
- int[,] matrix = new int[8, 8];
- int currentRow = 0;
- int currentCol = 7;
- matrix[currentRow, currentCol] = 1;
- int nextRow = 0;
- int nextCol = 0;
- for (int i = 0; i < allDirections.Count; i++)
- {
- switch (allDirections[i])
- {
- case "left up":
- nextRow = currentRow - 1;
- nextCol = currentCol - 2;
- break;
- case "left down":
- nextRow = currentRow + 1;
- nextCol = currentCol - 2;
- break;
- case "right up":
- nextRow = currentRow - 1;
- nextCol = currentCol + 2;
- break;
- case "right down":
- nextRow = currentRow + 1;
- nextCol = currentCol - 2;
- break;
- case "up left":
- nextRow = currentRow - 2;
- nextCol = currentCol - 1;
- break;
- case "up right":
- nextRow = currentRow - 2;
- nextCol = currentCol + 1;
- break;
- case "down left":
- nextRow = currentRow + 2;
- nextCol = currentCol - 1;
- break;
- case "down right":
- nextRow = currentRow + 2;
- nextCol = currentCol + 1;
- break;
- default:
- break;
- }
- if ((nextRow < 0 || nextRow >= 8) || (nextCol < 0 || nextCol >= 8))
- {
- continue;
- }
- currentRow = nextRow;
- currentCol = nextCol;
- matrix[currentRow, currentCol] = 1;
- }
- // ПРЕДПОЛАГАМ ЧЕ ОТ ТУК НАДОЛУ ГРЕША!
- string[] resultNumbers = new string[8];
- for (int row = 0; row < 8; row++)
- {
- string numberAsBinary = "";
- for (int col = 0; col < 8; col++)
- {
- numberAsBinary += matrix[row, col];
- }
- resultNumbers[row] = numberAsBinary;
- }
- int[] numbers = new int[resultNumbers.Length];
- for (int i = 0; i < resultNumbers.Length; i++)
- {
- numbers[i] = Convert.ToInt32(resultNumbers[i], 2);
- if (numbers[i] != 0)
- {
- Console.WriteLine(numbers[i]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement