Advertisement
Svetli0o

FormulaBit1

Mar 31st, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.91 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. namespace FormulaBit1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[,] matrix = new int[8, 8];
  14.             for (int i = 0; i < 8; i++)
  15.             {
  16.                 int num = int.Parse(Console.ReadLine());
  17.                 for (int j = 0; j < 8; j++)
  18.                 {
  19.                     matrix[i, j] = (num >> j) & 1;
  20.                 }
  21.             }
  22.             string direction = "south";
  23.             string previousDirection = "south";
  24.             int row = 0;
  25.             int col = 0;
  26.             int track = 1;
  27.             int turns = 0;
  28.             while (true)
  29.             {
  30.                 if (matrix[0, 0] == 1)
  31.                 {
  32.                     track--;
  33.                     break;
  34.                 }
  35.                 if (direction == "south")
  36.                 {
  37.                     if ((row == 7) || matrix[row + 1, col] == 1)
  38.                     {
  39.                         if (col == 7 || matrix[row, col + 1] == 1)
  40.                         {
  41.                             break;
  42.                         }
  43.                         previousDirection = "south";
  44.                         direction = "west";
  45.                         track++;
  46.                         turns++;
  47.                         col++;
  48.                     }
  49.                     else if (matrix[row + 1, col] == 0)
  50.                     {
  51.                         row++;
  52.                         track++;
  53.                     }
  54.                 }
  55.                 if (direction == "west")
  56.                 {
  57.                     if ((col == 7) || (matrix[row, col + 1] == 1))
  58.                     {
  59.                         if (previousDirection == "south")
  60.                         {
  61.                             if (row == 0 || matrix[row - 1, col] == 1)
  62.                             {
  63.                                 break;
  64.                             }
  65.                             previousDirection = "west";
  66.                             direction = "north";
  67.                             row--;
  68.                         }
  69.                         else
  70.                         {
  71.                             if (row == 7 || matrix[row + 1, col] == 1)
  72.                             {
  73.                                 break;
  74.                             }
  75.                             previousDirection = "west";
  76.                             direction = "south";
  77.                             row++;
  78.                         }
  79.                         track++;
  80.                         turns++;
  81.                     }
  82.                     else if (matrix[row, col + 1] == 0)
  83.                     {
  84.                         col++;
  85.                         track++;
  86.                     }
  87.                 }
  88.                 if (direction == "north")
  89.                 {
  90.                     if ((row == 0) || (matrix[row - 1, col] == 1))
  91.                     {
  92.                         if (col == 7 || matrix[row, col + 1] == 1)
  93.                         {
  94.                             break;
  95.                         }
  96.                         previousDirection = "north";
  97.                         direction = "west";
  98.                         track++;
  99.                         turns++;
  100.                         col++;
  101.                     }
  102.                     else if (matrix[row - 1, col] == 0)
  103.                     {
  104.                         row--;
  105.                         track++;
  106.                     }
  107.                 }
  108.             }
  109.             if (row == 7 && col == 7)
  110.             {
  111.                 Console.Write(track + " ");
  112.                 Console.Write(turns);
  113.                 Console.WriteLine();
  114.             }
  115.             else
  116.             {
  117.                 Console.Write("No ");
  118.                 Console.Write(track);
  119.                 Console.WriteLine();
  120.             }
  121.         }
  122.     }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement