Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class FormulaBit1
- {
- static void Main()
- {
- int[,] track = new int[8, 8];
- for (int i = 0; i < 8; i++)
- {
- int number = int.Parse(Console.ReadLine());
- for (int j = 0; j < 8; j++)
- {
- track[i, j] = ((number >> j) & 1);
- }
- }
- int row = 0;
- int col = 0;
- int pathCount = 0;
- int directionCount = 0;
- bool exitFound = false;
- string direction = "south";
- string lastDirectiom = "south";
- while (true)
- {
- if (track[row, col] != 0)
- {
- break;
- }
- pathCount++;
- if (row == 7 && col == 7)
- {
- exitFound = true;
- break;
- }
- if (direction == "south" && ((row == 7) || (row < 7 && (track [(row + 1), col] != 0))))
- {
- direction = "west";
- lastDirectiom = "south";
- directionCount++;
- if ((col < 7 && track[row, (col + 1)] != 0) || col == 7)
- {
- break;
- }
- }
- else if (direction == "west" && lastDirectiom == "south" && ((col == 7) || (col < 7 && (track[row, (col + 1)] != 0))))
- {
- direction = "north";
- lastDirectiom = "west";
- directionCount++;
- if ((row > 0 && track[(row - 1), col] != 0) || row == 0)
- {
- break;
- }
- }
- else if (direction == "north" && lastDirectiom == "west" && ((row == 0) || (row > 0 && (track[(row - 1), col] != 0))))
- {
- direction = "west";
- lastDirectiom = "north";
- directionCount++;
- if ((col < 7 && track[row, (col + 1)] != 0) || col == 7)
- {
- break;
- }
- }
- else if (direction == "west" && lastDirectiom == "north" && ((col == 7) || ( col < 7 && (track[row, (col + 1)] != 0))))
- {
- direction = "south";
- lastDirectiom = "west";
- directionCount++;
- if ((row < 7 && track[(row + 1), col] != 0) || row == 7)
- {
- break;
- }
- }
- if (direction == "south")
- {
- row++;
- }
- else if (direction == "west")
- {
- col++;
- }
- else if (direction == "north")
- {
- row--;
- }
- }
- if (exitFound)
- {
- Console.WriteLine("{0} {1}", pathCount, directionCount);
- }
- else
- {
- Console.WriteLine("No {0}", pathCount);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement