Advertisement
Nikolay_Kashev

Rectangle Position

May 27th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1. using System;
  2. using System.Drawing;
  3. using System.Linq;
  4.  
  5. namespace _06._Rectangle_Position
  6. {
  7.     public class Rectangle
  8.     {
  9.         public int Top { get; set; }
  10.         public int Left { get; set; }
  11.         public int Width { get; set; }
  12.         public int Height { get; set; }
  13.  
  14.         public int Right { get { return Left + Width; } }
  15.         public int Bottom { get { return Top + Height; } }
  16.  
  17.         public bool IsInside(Rectangle r)
  18.         {
  19.             return (r.Left <= Left) && (r.Right >= Right) &&
  20.                (r.Top <= Top) && (r.Bottom >= Bottom);
  21.         }
  22.     }
  23.  
  24.     class Program
  25.     {
  26.         static void Main(string[] args)
  27.         {
  28.             Rectangle r1 = ReadRectangle(), r2 = ReadRectangle();
  29.             Console.WriteLine(r1.IsInside(r2) ? "Inside" :
  30.               "Not inside");
  31.         }
  32.  
  33.         public static Rectangle ReadRectangle()
  34.         {
  35.             var size = Console.ReadLine().Split().Select(int.Parse);
  36.             Rectangle rectangle = new Rectangle()
  37.             {
  38.                 Left = size.First(),
  39.                 Top = size.Skip(1).First(),
  40.                 Width = size.Skip(2).First(),
  41.                 Height = size.Skip(3).First()
  42.             };
  43.             return rectangle;
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement