Advertisement
fbinnzhivko

05.00 Paint Ball

Apr 14th, 2016
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.25 KB | None | 0 0
  1. using System;
  2. class PaintBall
  3. {
  4.     static void Main()
  5.     {
  6.  
  7.         int[,] matrix = new int[10, 10];
  8.         for (int i = 0; i < 10; i++)
  9.         {
  10.             for (int j = 0; j < 10; j++)
  11.             {
  12.                 matrix[i, j] = 1;
  13.             }
  14.         }
  15.  
  16.         string shot = Console.ReadLine();
  17.         int numberOfShot = 1; // I need this to keep track of the white and black paints.
  18.  
  19.         while (shot != "End")
  20.         {
  21.             string[] shotString = shot.Split(' ');
  22.             int[] shotImpact = new int[3];
  23.             for (int i = 0; i < 3; i++)
  24.             {
  25.                 shotImpact[i] = int.Parse(shotString[i]); // converting the numbers to int           
  26.             }
  27.  
  28.             int lowRow = GettingTheLowRow(shotImpact[0], shotImpact[2]); // getting the low row and check if it gets outside the array.
  29.             int highRow = GettingTheHighRow(shotImpact[0], shotImpact[2]); // getting the high row and check if it gets outside the array.
  30.             int lowColon = GettingTheLowColon(shotImpact[1], shotImpact[2]); // same but for colon
  31.             int highColon = GettingTheHighColon(shotImpact[1], shotImpact[2]);
  32.  
  33.             if (numberOfShot % 2 == 1) // painting black zeros
  34.             {
  35.                 for (int i = lowRow; i <= highRow; i++)
  36.                 {
  37.                     for (int j = lowColon; j <= highColon; j++)
  38.                     {
  39.                         matrix[i, j] = 0;
  40.                     }
  41.                 }
  42.             }
  43.             else if (numberOfShot % 2 == 0) // painting white ones
  44.             {
  45.                 for (int i = lowRow; i <= highRow; i++)
  46.                 {
  47.                     for (int j = lowColon; j <= highColon; j++)
  48.                     {
  49.                         matrix[i, j] = 1;
  50.                     }
  51.                 }
  52.             }
  53.  
  54.             numberOfShot++; // keeping track of shots
  55.             shot = Console.ReadLine(); // next shot
  56.         }
  57.  
  58.         long result = 0;
  59.         string rowBinary = "";
  60.  
  61.         for (int row = 0; row < 10; row++)
  62.         {
  63.             for (int col = 9; col >= 0; col--)
  64.             {
  65.                 rowBinary += matrix[row, col];
  66.             }
  67.             result += Convert.ToInt64(rowBinary, 2);
  68.             rowBinary = "";
  69.         }
  70.         Console.WriteLine(result);
  71.     }
  72.  
  73.     private static int GettingTheLowColon(int col, int radius)
  74.     {
  75.         if (col - radius < 0)
  76.         {
  77.             col = 0;
  78.         }
  79.         else
  80.         {
  81.             col -= radius;
  82.         }
  83.         return col;
  84.     }
  85.     private static int GettingTheHighColon(int col, int radius)
  86.     {
  87.         if (col + radius > 9)
  88.         {
  89.             col = 9;
  90.         }
  91.         else
  92.         {
  93.             col += radius;
  94.         }
  95.         return col;
  96.     }
  97.     private static int GettingTheHighRow(int row, int radius)
  98.     {
  99.         if (row + radius > 9)
  100.         {
  101.             row = 9;
  102.         }
  103.         else
  104.         {
  105.             row += radius;
  106.         }
  107.         return row;
  108.     }
  109.  
  110.     private static int GettingTheLowRow(int row, int radius)
  111.     {
  112.         if (row - radius < 0)
  113.         {
  114.             row = 0;
  115.         }
  116.         else
  117.         {
  118.             row -= radius;
  119.         }
  120.         return row;
  121.     }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement