Advertisement
ntodorova

28.12-05.BitBall

Dec 31st, 2012
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.06 KB | None | 0 0
  1. using System;
  2.  
  3. class BitBall
  4. {
  5.     static void Main()
  6.     {
  7.         int[,] matrixTop = new int[8, 8];
  8.  
  9.         for (int row = 0; row <= 7; row++)
  10.         {
  11.             int bitsTop = int.Parse(Console.ReadLine());
  12.  
  13.             for (int col = 0; col <= 7; col++)
  14.             {
  15.                 matrixTop[row, col] = (bitsTop >> (7 - col)) & 1;
  16.             }
  17.         }
  18.  
  19.         int[,] matrixBottom = new int[8, 8];
  20.  
  21.         for (int row = 0; row <= 7; row++)
  22.         {
  23.             int bitsBottom = int.Parse(Console.ReadLine());
  24.  
  25.             for (int col = 0; col <= 7; col++)
  26.             {
  27.                 matrixBottom[row, col] = (bitsBottom >> (7 - col)) & 1;
  28.             }
  29.         }
  30.  
  31.         int[,] matrixNew = new int[8, 8];
  32.  
  33.         for (int row = 0; row <= 7; row++)
  34.         {
  35.             for (int col = 0; col <= 7; col++)
  36.             {
  37.  
  38.                 if (matrixTop[row, 7 - col] == 1 && matrixBottom[row, 7 - col] == 0)
  39.                 {
  40.                     matrixNew[row, 7 - col] = 1;
  41.                 }
  42.  
  43.                 else if (matrixTop[row, 7 - col] == 0 && matrixBottom[row, 7 - col] == 1)
  44.                 {
  45.                     matrixNew[row, 7 - col] = 2;
  46.                 }
  47.                 else
  48.                 {
  49.                     matrixNew[row, 7 - col] = 0;
  50.                 }
  51.  
  52.             }
  53.         }
  54.  
  55.         int[,] matrixNewTop = matrixNew;
  56.  
  57.         for (int i = 0; i <= 7; i++)
  58.         {
  59.             //Attack Top - 1
  60.             for (int col = 0; col <= 7; col++)
  61.             {
  62.                 for (int row = 0; row < 7; row++)
  63.                 {
  64.                     if (matrixNew[row, col] == 1 && matrixNew[row + 1, col] != 2)
  65.                     {
  66.                         matrixNewTop[row, col] = 0;
  67.                         matrixNewTop[row + 1, col] = 1;
  68.                     }
  69.                 }
  70.             }
  71.         }
  72.  
  73.         int topResult = 0;
  74.  
  75.         for (int col = 0; col <= 7; col++)
  76.         {
  77.             if (matrixNewTop[7, col] == 1)
  78.             {
  79.                 topResult++;
  80.             }
  81.         }
  82.  
  83.         int[,] matrixNewBottom = matrixNew;
  84.  
  85.         for (int i = 0; i <= 7; i++)
  86.         {
  87.             //Attack Bottom - 2
  88.             for (int col = 0; col <= 7; col++)
  89.             {
  90.                 for (int row = 7; row > 0; row--)
  91.                 {
  92.                     if (matrixNew[row, col] == 2 && matrixNew[row - 1, col] != 1)
  93.                     {
  94.                         matrixNewBottom[row, col] = 0;
  95.                         matrixNewBottom[row - 1, col] = 2;
  96.                     }
  97.                 }
  98.             }
  99.         }
  100.  
  101.         int bottomResult = 0;
  102.  
  103.         for (int col = 0; col <= 7; col++)
  104.         {
  105.             if (matrixNewBottom[0, col] == 2)
  106.             {
  107.                 bottomResult++;
  108.             }
  109.         }
  110.  
  111.         Console.WriteLine("{0}:{1}", topResult, bottomResult);
  112.     }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement