grach

Point in the Figure

Jul 13th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.35 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Point_in_the_Figure
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.             int h = int.Parse(Console.ReadLine());
  15.  
  16.             int x = int.Parse(Console.ReadLine());
  17.             int y = int.Parse(Console.ReadLine());
  18.  
  19.             int botTrectXStart = 0;
  20.             int botTrectXEnd = 3*h;
  21.  
  22.             int botTrectYStart = 0;
  23.             int botTrectYEnd = h;
  24.  
  25.             int topRectXstart = h;
  26.             int topRectXEnd = 2*h;
  27.  
  28.             int topRectYstart = h;
  29.             int topRectYend = 4*h;
  30.  
  31.             int isInBotRect = -2; //-1,0,1
  32.             int isInTopRect = -2;  //-1,0,1
  33.  
  34.             bool onMiddleLine = (x < h || x > 2 * h);
  35.  
  36.  
  37.             if ((x >= botTrectXStart && x <= botTrectXEnd) && (y >= botTrectYStart) && (y <= botTrectYEnd))
  38.             {
  39.                 if ((x == botTrectXStart || x == botTrectXEnd) || ((y == botTrectYStart) || (y == botTrectYEnd) && (onMiddleLine)))
  40.                 {
  41.                     isInBotRect = 0;
  42.                 }
  43.  
  44.                 else //Inside of bottom rectangle
  45.                 {
  46.                     isInBotRect = 1;
  47.                 }
  48.             }
  49.  
  50.             else
  51.             {
  52.                 isInBotRect = -1; //outside of bottom rectangle
  53.             }
  54.  
  55.             if ((x >= topRectXstart && x <= topRectXEnd) && (y >= topRectYstart) && (y <= topRectYend))
  56.             {
  57.                 if ((x == topRectXstart || x == topRectXEnd) || ((y == topRectYend) || (y == topRectYstart) && (onMiddleLine)))
  58.                 {
  59.                     isInTopRect = 0;
  60.                 }
  61.                 else //inside of top rect
  62.                 {
  63.                     isInBotRect = 1;
  64.                 }
  65.             }
  66.             else //inside of top rectangle
  67.             {
  68.                 isInTopRect = -1;
  69.             }
  70.  
  71.  
  72.             if ((isInBotRect == -1) && (isInTopRect == -1))
  73.             {
  74.                 Console.WriteLine("Outside");
  75.             }
  76.  
  77.             else if ((isInBotRect == 0) || (isInTopRect == 0))
  78.             {
  79.                 Console.WriteLine("Border");
  80.             }
  81.             else
  82.             {
  83.                 Console.WriteLine("inside");
  84.             }
  85.  
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment