Advertisement
dimov

Untitled

Jan 3rd, 2013
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.88 KB | None | 0 0
  1. using System;
  2.  
  3. class FormulaBit1
  4. {
  5.     static void Main()
  6.     {
  7.         byte[] grid = new byte[8]; //{ 2, 38, 28, 16, 71, 143, 3, 43 };
  8.         byte flag = 0;
  9.         byte path = 0;
  10.         byte dir = 0;
  11.         byte checker = 0;
  12.         bool champ = false;
  13.         bool run = true;
  14.         byte x = 0;
  15.         byte y = 0;
  16.         byte mask = 1;
  17.         for (byte i = 0; i < 8; i++)
  18.         {
  19.             grid[i] = byte.Parse(Console.ReadLine());
  20.         }
  21.         while (run==true)
  22.         {
  23.             mask = 1;
  24.             switch (flag)
  25.             {
  26.                 case 0:
  27.                     if (grid[0] % 2 == 0)
  28.                     {
  29.                         path++;
  30.                         flag = 1;
  31.                     }
  32.                     else
  33.                     {
  34.                         run = false;
  35.                     }
  36.                     break;
  37.                 case 1:
  38.                     if ((x + 1) < 8 && ((mask <<= y) & grid[x + 1]) == 0 )
  39.                     {
  40.                         path++;
  41.                         x++;
  42.                     }
  43.                     else
  44.                     {
  45.                         if (checker!=path)
  46.                         {
  47.                             flag = 2;
  48.                             dir++;
  49.                             checker = path;
  50.                         }
  51.                         else
  52.                         {
  53.                             run = false;
  54.                         }
  55.                     }
  56.                     break;
  57.                 case 2:
  58.                     if ((y + 1) < 8 && ((mask <<= (y + 1)) & grid[x]) == 0 )
  59.                     {
  60.                         path++;
  61.                         y++;
  62.                     }
  63.                     else
  64.                     {
  65.                         if (checker!=path)
  66.                         {
  67.                             flag = 3;
  68.                             dir++;
  69.                             checker = path;
  70.                         }
  71.                         else
  72.                         {
  73.                             run = false;
  74.                         }
  75.                     }
  76.                     break;
  77.                 case 3:
  78.                     if ((x-1) >= 0 && ((mask <<= y) & grid[x - 1]) == 0)
  79.                     {
  80.                         path++;
  81.                         x--;
  82.                     }
  83.                     else
  84.                     {
  85.                         if (checker!=path)
  86.                         {
  87.                             flag = 4;
  88.                             dir++;
  89.                             checker = path;
  90.                         }
  91.                         else
  92.                         {
  93.                             run = false;
  94.                         }
  95.                     }
  96.                     break;
  97.                 case 4:
  98.                     if ((y+1)<8 && (((mask <<= y+1) & grid[x]) == 0) )
  99.                     {
  100.                         path++;
  101.                         y++;
  102.                     }
  103.                     else
  104.                     {
  105.                         if (checker!=path)
  106.                         {
  107.                             flag = 1;
  108.                             dir++;
  109.                             checker = path;
  110.                         }
  111.                         else
  112.                         {
  113.                             run = false;
  114.                         }
  115.                     }
  116.                     break;
  117.                 default: Console.WriteLine("ne stava brat");
  118.                     break;
  119.             }
  120.             if (y==7 && x==7)
  121.             {
  122.                 champ = true;
  123.                 run = false;
  124.             }
  125.         }
  126.         if (run==false && champ == false)
  127.         {
  128.             Console.WriteLine("No {0}",path);    
  129.         }
  130.         if (champ==true)
  131.         {
  132.             Console.WriteLine("{0} {1}", path, dir);
  133.         }
  134.     }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement