Advertisement
sashomaga

BitBall

Dec 30th, 2012
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.18 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class Program
  5. {
  6.     static void Main()
  7.     {
  8.         int[] first = new int[8]; //input data for top team
  9.         int[] second = new int[8]; //input data for bottom team
  10.  
  11.         int[,] matrix1 = new int[8, 8]; //matrix to store top team
  12.         int[,] matrix2 = new int[8, 8]; // matrix to store bottom team
  13.  
  14.         int[] score1 = new int[8]; //array to store score of top team to avoid more than 1 point for 1 column // top team score
  15.         int[] score2 = new int[8]; //bottom team score
  16.         //matrix 1
  17.         for (int x = 0; x < 8; x++) //set 1 where are players
  18.         {
  19.             first[x] = int.Parse(Console.ReadLine()); //read from console
  20.             for (int y = 0, reverse = 7; y < 8; y++, reverse--) //use reverse to denote player at exact position
  21.             {
  22.                 if ((first[x] >> y & 1) == 1) //bitwise check for 1
  23.                 {
  24.                     matrix1[x, reverse] = 1; //fill matrix
  25.                 }
  26.             }
  27.         }
  28.         //matrix2
  29.         for (int x = 0; x < 8; x++)
  30.         {
  31.             second[x] = int.Parse(Console.ReadLine());
  32.             for (int y = 0, reverse = 7; y < 8; y++, reverse--)
  33.             {
  34.                 if ((second[x] >> y & 1) == 1)
  35.                 {
  36.                     matrix2[x, reverse] = 1;
  37.                 }
  38.             }
  39.         }
  40.  
  41.         //score 1
  42.         bool check = true;
  43.  
  44.  
  45.         for (int x = 0; x < 8; x++)
  46.         {
  47.  
  48.             for (int y = 0; y < 8; y++)
  49.             {
  50.  
  51.                 if (matrix1[x, y] == 1) //player exist
  52.                 {
  53.  
  54.                     if (x == 7) //useless row
  55.                     {
  56.                         score1[y]++;
  57.                         continue;
  58.                     }
  59.                     for (int i = x + 1; i < 8; i++) //check in matrix2 down for opposite team player
  60.                     {
  61.                         if (matrix2[i, y] == 1)
  62.                         {
  63.                             check = false; // set false if player exist
  64.                         }
  65.                     }
  66.                     if (check == true)
  67.                     {
  68.                         score1[y]++; // + 1 score for this column
  69.                     }
  70.                 }
  71.                 check = true;
  72.  
  73.             }
  74.         }
  75.         //score 2
  76.         for (int x = 0; x < 8; x++)
  77.         {
  78.  
  79.             for (int y = 0; y < 8; y++)
  80.             {
  81.                 if (matrix2[x, y] == 1) //player exist
  82.                 {
  83.                     if (x == 0) //useless row
  84.                     {
  85.                         score2[y]++;
  86.                         continue;
  87.                     }
  88.                     for (int i = x - 1; i >= 0; i--) //check in matrix1 up for opposite player
  89.                     {
  90.                         if (matrix1[i, y] == 1)
  91.                         {
  92.                             check = false; //false if player exist
  93.                         }
  94.                     }
  95.                     if (check == true)
  96.                     {
  97.                         score2[y]++; //+1 score for this column
  98.                     }
  99.                 }
  100.                 check = true;
  101.  
  102.             }
  103.         }
  104.         ////print1
  105.         //for (int x = 0; x < 8; x++)
  106.         //{
  107.         //    for (int y = 0; y < 8; y++)
  108.         //    {
  109.         //        Console.Write(matrix1[x, y]);
  110.         //    }
  111.         //    Console.WriteLine();
  112.         //}
  113.         //Console.WriteLine();
  114.         ////print2
  115.         //for (int x = 0; x < 8; x++)
  116.         //{
  117.         //    for (int y = 0; y < 8; y++)
  118.         //    {
  119.         //        Console.Write(matrix2[x, y]);
  120.         //    }
  121.         //    Console.WriteLine();
  122.         //}
  123.         //Console.WriteLine();
  124.  
  125.         //score1
  126.         int res1 = 0;
  127.         foreach (var item in score1) //calc score
  128.         {
  129.             if (item > 0)
  130.             {
  131.                 res1++;
  132.             }
  133.         }
  134.         //score2
  135.         int res2 = 0;
  136.         foreach (var item in score2)
  137.         {
  138.             if (item > 0)
  139.             {
  140.                 res2++;
  141.             }
  142.         }
  143.  
  144.         Console.WriteLine(res1 + ":" + res2);
  145.     }
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement