Advertisement
fbinnzhivko

02.01 Take The Plane Down

Mar 17th, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.73 KB | None | 0 0
  1. using System;
  2. /*
  3.     You will be given coordinates (x,y) of your headquarters and the distance to the borders.
  4.     On the next line you will receive the number of the fighters that are approaching your country.
  5.     After that for the next N * 2 lanes you will be given all the planes coordinates.
  6.  
  7.     You need to calculate the distance to every one of them and if they are inside your country shoot them.
  8.     For every plane you destroy you need to print a message for it on the console:
  9.     You destroyed a plane at [x,y]. Where x and y are the coordinates of the plane.
  10.  */
  11. class TakeThePlaneDown
  12. {
  13.     static void Main()
  14.     {
  15.         int x = int.Parse(Console.ReadLine());
  16.         int y = int.Parse(Console.ReadLine());
  17.         int border = int.Parse(Console.ReadLine());
  18.         int planeNumber = int.Parse(Console.ReadLine());
  19.  
  20.         for (int i = 0; i < planeNumber; i++)
  21.         {
  22.             int xPlaneCoord = int.Parse(Console.ReadLine());
  23.             int yPlaneCoord = int.Parse(Console.ReadLine());
  24.  
  25.             bool inMyAreaX = (xPlaneCoord <= (border - x)) || (xPlaneCoord <= (border + x));
  26.             bool inMyAreaY = (yPlaneCoord <= (border - y)) || (yPlaneCoord <= (border + y));
  27.  
  28.             int greaterX = Math.Max(x, xPlaneCoord);
  29.             int smallerX = Math.Min(x, xPlaneCoord);
  30.             int greaterY = Math.Max(y, yPlaneCoord);
  31.             int smallerY = Math.Min(y, yPlaneCoord);
  32.  
  33.             if (greaterX - smallerX > border || greaterY - smallerY > border)
  34.             {
  35.                 continue;
  36.             }
  37.  
  38.             if (inMyAreaX && inMyAreaY)
  39.             {
  40.                 Console.WriteLine("You destroyed a plane at [{0},{1}]", xPlaneCoord, yPlaneCoord);
  41.             }
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement