Advertisement
milislavski

KnightPath

Mar 24th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. class KnightPath
  8. {
  9.     static void Main()
  10.     {
  11.         string direction = Console.ReadLine();
  12.         var allDirections = new List<string>();
  13.         allDirections.Add(direction);
  14.  
  15.         while (true)
  16.         {
  17.             direction = Console.ReadLine();
  18.             if (direction == "stop")
  19.             {
  20.                 break;
  21.             }
  22.             allDirections.Add(direction);
  23.         }
  24.  
  25.         int[,] matrix = new int[8, 8];
  26.         int currentRow = 0;
  27.         int currentCol = 7;
  28.         matrix[currentRow, currentCol] = 1;
  29.         int nextRow = 0;
  30.         int nextCol = 0;
  31.         for (int i = 0; i < allDirections.Count; i++)
  32.         {
  33.             switch (allDirections[i])
  34.             {
  35.                 case "left up":
  36.                     nextRow = currentRow - 1;
  37.                     nextCol = currentCol - 2;
  38.                     break;
  39.                 case "left down":
  40.                     nextRow = currentRow + 1;
  41.                     nextCol = currentCol - 2;
  42.                     break;
  43.                 case "right up":
  44.                     nextRow = currentRow - 1;
  45.                     nextCol = currentCol + 2;
  46.                     break;
  47.                 case "right down":
  48.                     nextRow = currentRow + 1;
  49.                     nextCol = currentCol - 2;
  50.                     break;
  51.                 case "up left":
  52.                     nextRow = currentRow - 2;
  53.                     nextCol = currentCol - 1;
  54.                     break;
  55.                 case "up right":
  56.                     nextRow = currentRow - 2;
  57.                     nextCol = currentCol + 1;
  58.                     break;
  59.                 case "down left":
  60.                     nextRow = currentRow + 2;
  61.                     nextCol = currentCol - 1;
  62.                     break;
  63.                 case "down right":
  64.                     nextRow = currentRow + 2;
  65.                     nextCol = currentCol + 1;
  66.                     break;
  67.                 default:
  68.                     break;
  69.             }
  70.             if ((nextRow < 0 || nextRow >= 8) || (nextCol < 0 || nextCol >= 8))
  71.             {
  72.                 continue;
  73.             }
  74.  
  75.             currentRow = nextRow;
  76.             currentCol = nextCol;
  77.             matrix[currentRow, currentCol] = 1;
  78.         }
  79.  
  80.         // ПРЕДПОЛАГАМ ЧЕ ОТ ТУК НАДОЛУ ГРЕША!
  81.  
  82.         string[] resultNumbers = new string[8];
  83.  
  84.         for (int row = 0; row < 8; row++)
  85.         {
  86.             string numberAsBinary = "";
  87.             for (int col = 0; col < 8; col++)
  88.             {
  89.                 numberAsBinary += matrix[row, col];
  90.  
  91.             }
  92.             resultNumbers[row] = numberAsBinary;
  93.  
  94.         }
  95.         int[] numbers = new int[resultNumbers.Length];
  96.         for (int i = 0; i < resultNumbers.Length; i++)
  97.         {
  98.             numbers[i] = Convert.ToInt32(resultNumbers[i], 2);
  99.             if (numbers[i] != 0)
  100.             {
  101.                 Console.WriteLine(numbers[i]);
  102.             }
  103.         }
  104.     }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement