Advertisement
ad2bg

PointInTheFigure

Oct 28th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.08 KB | None | 0 0
  1. namespace PointInTheFigure
  2. {
  3.     using System;
  4.  
  5.     public static class PointInTheFigure
  6.     {
  7.         public static void Main()
  8.         {
  9.             int h = int.Parse(Console.ReadLine());
  10.             int x = int.Parse(Console.ReadLine());
  11.             int y = int.Parse(Console.ReadLine());
  12.  
  13.             bool border = (y == 0 && InRange(x, 0, 3 * h)); // horizonal bottom border
  14.             border = border || ((x == 0 || x == 3 * h) && InRange(y, 0, h)); // add bottom vertical borders
  15.             border = border || ((y == h) && (InRange(x, 0, h) || InRange(x, 2 * h, 3 * h))); // add top horizontal borders
  16.             border = border || ((x == h || x == 2 * h) && InRange(y, h, 4 * h));// add top vertical borders
  17.             border = border || ((y == 4 * h) && InRange(x, h, 2 * h)); // add top horizontal border
  18.  
  19.             if (border) { Console.WriteLine("border"); return; }
  20.  
  21.             bool inside = InRange(x, 0, 3 * h) && InRange(y, 0, h); // in base
  22.             inside = inside || (InRange(x, h, 2 * h) && InRange(y, 0, 4 * h)); // add in pillar
  23.  
  24.             if (inside)
  25.             {
  26.                 Console.WriteLine("inside");
  27.             }
  28.             else
  29.             {
  30.                 Console.WriteLine("outside");
  31.             }
  32.  
  33.             //bool outR1 = x < 0 || 3 * h < x || y < 0 || h < y;
  34.             //bool outR2 = x < h || 2 * h < x || y < h || 4 * h < y;
  35.  
  36.             //bool inR1 = 0 < x && x < 3 * h && 0 < y && y < h;
  37.             //bool inR2 = h < x && x < 2 * h && h < y && y < 4 * h;
  38.  
  39.             //bool commonBorder = (x > h && x < 2 * h) && y == h;
  40.  
  41.             //if (outR1 && outR2)
  42.             //{
  43.             //    Console.WriteLine("outside");
  44.             //}
  45.             //else if (inR1 || inR2 || commonBorder)
  46.             //{
  47.             //    Console.WriteLine("inside");
  48.             //}
  49.             //else
  50.             //{
  51.             //    Console.WriteLine("border");
  52.             //}
  53.         }
  54.  
  55.         public static bool InRange(double x, double x1, double x2) => (Math.Min(x1, x2) <= x) && (x <= Math.Max(x1, x2));
  56.  
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement