tanya_zheleva

Untitled

Feb 11th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.08 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ExamPreparation
  6. {
  7.     public sealed class Startu
  8.     {
  9.         public static void Main()
  10.         {
  11.             double[] firstCoordinates = Console.ReadLine()
  12.                 .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  13.                 .Select(double.Parse)
  14.                 .ToArray();
  15.             double[] secondCoordinates = Console.ReadLine()
  16.                 .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  17.                 .Select(double.Parse)
  18.                 .ToArray();
  19.  
  20.             Rectangle first = new Rectangle(firstCoordinates[0], firstCoordinates[1], firstCoordinates[2], firstCoordinates[3]);
  21.             Rectangle second = new Rectangle(secondCoordinates[0], secondCoordinates[1], secondCoordinates[2], secondCoordinates[3]);
  22.  
  23.             bool isInside = first.Left >= second.Left &&
  24.                                  first.Right <= second.Right &&
  25.                                  first.Top <= second.Top &&
  26.                                  first.Bottom <= second.Bottom;
  27.  
  28.             if (isInside)
  29.             {
  30.                 Console.WriteLine("Inside");
  31.             }
  32.             else
  33.             {
  34.                 Console.WriteLine("Not inside");
  35.             }
  36.         }
  37.     }
  38.  
  39.     public sealed class Rectangle
  40.     {
  41.         public Rectangle(double left, double top, double width, double height)
  42.         {
  43.             this.Left = left;
  44.             this.Top = top;
  45.             this.Width = width;
  46.             this.Height = height;
  47.         }
  48.  
  49.         public double Left { get; private set; }
  50.  
  51.         public double Top { get; private set; }
  52.  
  53.         public double Width { get; private set; }
  54.  
  55.         public double Height { get; private set; }
  56.  
  57.         public double Right
  58.         {
  59.             get
  60.             {
  61.                 return this.Left + this.Width;
  62.             }
  63.         }
  64.  
  65.         public double Bottom
  66.         {
  67.             get
  68.             {
  69.                 return this.Top + this.Height;
  70.             }
  71.         }
  72.     }
  73. }
Add Comment
Please, Sign In to add comment