Advertisement
ivan_yosifov

Bit_Ball

Dec 2nd, 2013
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.04 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5.     static void Main()
  6.     {
  7.         char[,] topTeam = new char[8, 8];
  8.         char[,] bottomTeam = new char[8, 8];
  9.         char[,] field = new char[8, 8];
  10.         int topScore = 0;
  11.         int bottomScore = 0;
  12.  
  13.         // Read top team players
  14.         for (int i = 0; i < 8; i++)
  15.         {
  16.             int number = int.Parse(Console.ReadLine());
  17.             for (int j = 7; j >= 0; j--)
  18.             {
  19.                 int bit = (number >> j) & 1;
  20.                 if (bit == 1)
  21.                 {
  22.                     topTeam[i, j] = 'T';
  23.                 }
  24.                 else
  25.                 {
  26.                     topTeam[i, j] = ' ';
  27.                 }
  28.             }
  29.         }
  30.  
  31.         // Read bottom team players
  32.         for (int i = 0; i < 8; i++)
  33.         {
  34.             int number = int.Parse(Console.ReadLine());
  35.             for (int j = 7; j >= 0; j--)
  36.             {
  37.                 int bit = (number >> j) & 1;
  38.                 if (bit == 1)
  39.                 {
  40.                     bottomTeam[i, j] = 'B';
  41.                 }
  42.                 else
  43.                 {
  44.                     bottomTeam[i, j] = ' ';
  45.                 }
  46.             }
  47.         }
  48.  
  49.         // Create common field
  50.         for (int i = 0; i < 8; i++)
  51.         {
  52.             for (int j = 7; j >= 0; j--)
  53.             {
  54.                 char topPlayer = topTeam[i, j];
  55.                 char bottomPlayer = bottomTeam[i, j];
  56.  
  57.                 if (topPlayer == ' ' && bottomPlayer == ' ')
  58.                 {
  59.                     field[i, j] = ' ';
  60.                 }
  61.                 else if (topPlayer == 'T' && bottomPlayer == 'B')
  62.                 {
  63.                     field[i, j] = ' ';
  64.                 }
  65.                 else if (topPlayer == 'T' && bottomPlayer == ' ')
  66.                 {
  67.                     field[i, j] = 'T';
  68.                 }
  69.                 else if (topPlayer == ' ' && bottomPlayer == 'B')
  70.                 {
  71.                     field[i, j] = 'B';
  72.                 }
  73.             }
  74.         }
  75.  
  76.         // Get bottom score - count columns from top to bottom
  77.         for (int col = 7; col >= 0; col--)
  78.         {
  79.             for (int row = 0; row < 8; row++)
  80.             {
  81.                 if (field[row, col] == 'T')
  82.                 {
  83.                     break;
  84.                 }
  85.                 else if (field[row, col] == 'B')
  86.                 {
  87.                     bottomScore++;
  88.                     break;
  89.                 }
  90.             }
  91.         }
  92.  
  93.         // Get top score - count columns from bottom to top
  94.         for (int col = 7; col >= 0; col--)
  95.         {
  96.             for (int row = 7; row >= 0; row--)
  97.             {
  98.                 if (field[row, col] == 'T')
  99.                 {
  100.                     topScore++;
  101.                     break;
  102.                 }
  103.                 else if (field[row, col] == 'B')
  104.                 {
  105.                     break;
  106.                 }
  107.             }
  108.         }
  109.  
  110.         // Print score
  111.         Console.WriteLine("{0}:{1}", topScore, bottomScore);
  112.     }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement