Advertisement
vkv1986

BitBall

Jan 9th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.00 KB | None | 0 0
  1. using System;
  2.  
  3. class BitBall
  4. {
  5.     static void Main()
  6.     {
  7.         bool isTop = true;
  8.         bool isTopGoal = true;
  9.         bool isBottomGoal = true;
  10.         int topGoal = 0;
  11.         int bottomGoal = 0;
  12.         byte[] top = new byte[8];
  13.         for (int count = 0; count < 8; count++)
  14.         {
  15.             top[count] = byte.Parse(Console.ReadLine());
  16.         }
  17.         byte[] bottom = new byte[8];
  18.         for (int count = 0; count < 8; count++)
  19.         {
  20.             bottom[count] = byte.Parse(Console.ReadLine());
  21.         }
  22.         byte[] field = new byte[8];
  23.         for (int count = 0; count < 8; count++)
  24.         {
  25.             field[count] = (byte)(top[count] ^ bottom[count]);
  26.         }
  27.         for (int column = 0; column < 8; column++)
  28.         {
  29.             for (int row = 0; row < 8; row++)
  30.             {
  31.                 int mask = 1 << column;
  32.                 int maskNumber = mask & field[row];
  33.                 int bit = maskNumber >> column;
  34.                 if (bit == 1)
  35.                 {
  36.                     byte checkNumber = (byte)(field[row] & top[row]);
  37.                     int checkMask = 1 << column;
  38.                     int checkMaskNumber = checkMask & checkNumber;
  39.                     int checkBit = checkMaskNumber >> column;
  40.                     if (checkBit == 1)
  41.                     {
  42.                         isTop = true;
  43.                     }
  44.                     else
  45.                     {
  46.                         isTop = false;
  47.                     }
  48.                 }
  49.                 if (isTop && bit == 1)
  50.                 {
  51.                     for (int iteration = 1; iteration < 8 - row; iteration++)
  52.                     {
  53.                         int topMask = 1 << column;
  54.                         int topMaskNumber = topMask & field[row + iteration];
  55.                         int topBit = topMaskNumber >> column;
  56.                         if (topBit == 1)
  57.                         {
  58.                             isTopGoal = false;
  59.                         }
  60.                     }
  61.                     if (isTopGoal)
  62.                     {
  63.                         topGoal++;
  64.                     }
  65.                     isTopGoal = true;
  66.                 }
  67.                 else if (!isTop && bit == 1)
  68.                 {
  69.                     for (int iteration = 1; iteration <= row; iteration++)
  70.                     {
  71.                         int bottomMask = 1 << column;
  72.                         int bottomMaskNumber = bottomMask & field[row - iteration];
  73.                         int bottomBit = bottomMaskNumber >> column;
  74.                         if (bottomBit == 1)
  75.                         {
  76.                             isBottomGoal = false;
  77.                         }
  78.                     }
  79.                     if (isBottomGoal)
  80.                     {
  81.                         bottomGoal++;
  82.                     }
  83.                     isBottomGoal = true;
  84.                 }
  85.             }
  86.         }
  87.         Console.WriteLine("{0}:{1}", topGoal, bottomGoal);
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement