Advertisement
dentia

AngryBits

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