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;
- namespace FormulaBit1
- {
- class FormulaBit1
- {
- static void Main(string[] args)
- {
- int[,] matrix = new int[8, 8];
- for (int i = 0; i < 8; i++)
- {
- int number = int.Parse(Console.ReadLine());
- for (int k = 0; k < 8; k++)
- {
- int mask = 1 << k;
- int m = mask & number;
- int bit = m >> k;
- matrix[i, k] = bit;
- }
- }
- int row = 0;
- int col = 0;
- int turns = 0;
- int steps = 0;
- string direction = "down";
- bool lastDirectionDown = true;
- bool exitFound = false;
- while (true)
- {
- if (matrix[row, col] == 1)
- {
- break;
- }
- steps++;
- if (row == 7 && col == 7)
- {
- exitFound = true;
- break;
- }
- if (direction == "down" && (row + 1 > 7 || matrix[row + 1, col] == 1))
- {
- direction = "left";
- if (col + 1 > 7 || matrix[row, col + 1] == 1)
- {
- break;
- }
- turns++;
- }
- else if (direction == "left" && (col + 1 > 7 || matrix[row, col + 1] == 1))
- {
- if (lastDirectionDown)
- {
- direction = "up";
- if (row - 1 < 0 || matrix[row - 1, col] == 1)
- {
- break;
- }
- turns++;
- lastDirectionDown = false;
- }
- else
- {
- direction = "down";
- if (row + 1 > 7 || matrix[row + 1, col] == 1)
- {
- break;
- }
- turns++;
- lastDirectionDown = true;
- }
- }
- else if (direction == "up" && (row - 1 < 0 || matrix[row - 1, col] == 1))
- {
- direction = "left";
- if (col + 1 > 7 || matrix[row, col + 1] == 1)
- {
- break;
- }
- turns++;
- }
- if (direction == "down")
- {
- row++;
- }
- else if (direction == "up")
- {
- row--;
- }
- else if (direction == "left")
- {
- col++;
- }
- }
- if (exitFound)
- {
- Console.WriteLine(steps + " " + turns);
- }
- else
- {
- Console.WriteLine("No " + steps);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement