Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class Program
- {
- static void Main()
- {
- var rectangles = new Dictionary<string, Rectangle>();
- int[] inputNums = Console.ReadLine().Split().Select(int.Parse).ToArray();
- AddRectangles(rectangles, inputNums[0]);
- CheckRectangles(rectangles, inputNums[1]);
- }
- private static void CheckRectangles(Dictionary<string, Rectangle> rectangles, int m)
- {
- for (int i = 0; i < m; i++)
- {
- string[] outputArgs = Console.ReadLine().Split();
- string firstId = outputArgs[0];
- string secondId = outputArgs[1];
- Console.WriteLine($"{Rectangle.rectOverlap(rectangles[firstId], rectangles[secondId])}".ToLower());
- }
- }
- private static void AddRectangles(Dictionary<string, Rectangle> rectangles, int n)
- {
- for (int i = 0; i < n; i++)
- {
- string[] rectangleArgs = Console.ReadLine().Split();
- string Id = rectangleArgs[0];
- double width = double.Parse(rectangleArgs[1]);
- double height = double.Parse(rectangleArgs[2]);
- double x = double.Parse(rectangleArgs[3]);
- double y = double.Parse(rectangleArgs[4]);
- Rectangle rectangle = new Rectangle(x, y, width, height);
- rectangles[Id] = rectangle;
- }
- }
- }
- //////////////////
- public class Rectangle
- {
- double x;
- double y;
- double width;
- double height;
- public Rectangle(double x, double y, double width, double height)
- {
- this.x = x;
- this.y = y;
- this.width = width;
- this.height = height;
- }
- private static bool valueInRange(double value, double min, double max)
- { return (value >= min) && (value <= max); }
- public static bool rectOverlap(Rectangle A, Rectangle B)
- {
- bool xOverlap = valueInRange(A.x, B.x, B.x + B.width) ||
- valueInRange(B.x, A.x, A.x + A.width);
- bool yOverlap = valueInRange(A.y, B.y, B.y + B.height) ||
- valueInRange(B.y, A.y, A.y + A.height);
- return xOverlap && yOverlap;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment