Advertisement
dimipan80

ExamTask_Problem 5 – Formula Bit 1

Apr 5th, 2014
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.94 KB | None | 0 0
  1. using System;
  2.  
  3. class FormulaBit1
  4. {
  5.     static void Main()
  6.     {
  7.         int[,] track = new int[8, 8];
  8.         for (int i = 0; i < 8; i++)
  9.         {
  10.             int number = int.Parse(Console.ReadLine());          
  11.  
  12.             for (int j = 0; j < 8; j++)
  13.             {
  14.                 track[i, j] = ((number >> j) & 1);
  15.             }
  16.         }
  17.         int row = 0;
  18.         int col = 0;
  19.         int pathCount = 0;
  20.         int directionCount = 0;
  21.         bool exitFound = false;
  22.         string direction = "south";
  23.         string lastDirectiom = "south";
  24.         while (true)
  25.         {
  26.             if (track[row, col] != 0)
  27.             {
  28.                 break;
  29.             }
  30.             pathCount++;
  31.             if (row == 7 && col == 7)
  32.             {
  33.                 exitFound = true;
  34.                 break;
  35.             }
  36.             if (direction == "south" && ((row == 7) || (row < 7 && (track [(row + 1), col] != 0))))
  37.             {
  38.                 direction = "west";
  39.                 lastDirectiom = "south";
  40.                 directionCount++;
  41.                 if ((col < 7 && track[row, (col + 1)] != 0) || col == 7)
  42.                 {
  43.                     break;
  44.                 }
  45.             }
  46.             else if (direction == "west" && lastDirectiom == "south" && ((col == 7) || (col < 7 && (track[row, (col + 1)] != 0))))
  47.             {
  48.                 direction = "north";
  49.                 lastDirectiom = "west";
  50.                 directionCount++;
  51.                 if ((row > 0 && track[(row - 1), col] != 0) || row == 0)
  52.                 {
  53.                     break;
  54.                 }
  55.             }
  56.             else if (direction == "north" && lastDirectiom == "west" && ((row == 0) || (row > 0 && (track[(row - 1), col] != 0))))
  57.             {
  58.                 direction = "west";
  59.                 lastDirectiom = "north";
  60.                 directionCount++;
  61.                 if ((col < 7 && track[row, (col + 1)] != 0) || col == 7)
  62.                 {
  63.                     break;
  64.                 }
  65.             }
  66.             else if (direction == "west" && lastDirectiom == "north" && ((col == 7) || ( col < 7 && (track[row, (col + 1)] != 0))))
  67.             {
  68.                 direction = "south";
  69.                 lastDirectiom = "west";
  70.                 directionCount++;
  71.                 if ((row < 7 && track[(row + 1), col] != 0) || row == 7)
  72.                 {
  73.                     break;
  74.                 }
  75.             }          
  76.             if (direction == "south")
  77.             {
  78.                 row++;
  79.             }
  80.             else if (direction == "west")
  81.             {
  82.                 col++;
  83.             }
  84.             else if (direction == "north")
  85.             {
  86.                 row--;
  87.             }
  88.         }
  89.         if (exitFound)
  90.         {
  91.             Console.WriteLine("{0} {1}", pathCount, directionCount);
  92.         }
  93.         else
  94.         {
  95.             Console.WriteLine("No {0}", pathCount);
  96.         }
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement