fbinnzhivko

05.001 Paint Ball

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