static void Main(string[] args) { int[] counts = Console.ReadLine().Split(new char[0], StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray(); Rectangle[] rectangles = new Rectangle[counts[0]]; for(int i = 0; i< counts[0]; i++) { string[] tokens = Console.ReadLine().Split(new char[0], StringSplitOptions.RemoveEmptyEntries); string id = tokens[0]; double width = double.Parse(tokens[1]); double height = double.Parse(tokens[2]); double x = double.Parse(tokens[3]); double y = double.Parse(tokens[4]); rectangles[i] = new Rectangle(id, width, height, x, y); } for(int i=0; i< counts[1]; i++) { string[] tokens = Console.ReadLine().Split(new char[0], StringSplitOptions.RemoveEmptyEntries); Rectangle rect1 = rectangles.Where(r => r.id == tokens[0]).First(); Rectangle rect2 = rectangles.Where(r => r.id == tokens[1]).First(); Console.WriteLine(rect1.Intersects(rect2)); } }
public string Intersects(Rectangle rectangle) { if((rectangle.y >= this.y && rectangle.y - rectangle.height <=this.y && rectangle.x <= this.x && rectangle.x+rectangle.width >= this.x) || (rectangle.y >= this.y && rectangle.y - rectangle.height <= this.y && rectangle.x >= this.x && rectangle.x <= this.x + this.width) || (rectangle.y <= this.y && rectangle.y >= this.y - this.height && rectangle.x <= this.x && rectangle.x + rectangle.width >= this.x) || (rectangle.y <= this.y && rectangle.y >= this.y - this.height && rectangle.x >= this.x && rectangle.x <= this.x + this.width)) { return "true"; } else { return "false"; } }
public static void Main() { int[] lines = Console.ReadLine() .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(int.Parse) .ToArray(); Dictionary<string, Rectangle> rectangles=new Dictionary<string, Rectangle>(); for (int i = 0; i < lines[0]; i++) { string[] input = Console.ReadLine().Split(' '); string ID = input[0].Trim(); double width = double.Parse(input[1]); double height = double.Parse(input[2]); double x = double.Parse(input[3]); double y = double.Parse(input[4]); if (!rectangles.ContainsKey(ID)) { rectangles.Add(ID, new Rectangle(ID, (int)x, (int)y, (int)width, (int)height)); } else { rectangles[ID]=new Rectangle( ID, (int)x, (int)y, (int)width, (int)height); } } for (int i = 0; i < lines[1]; i++) { string[] ids = Console.ReadLine().Split(' '); Console.WriteLine(rectangles[ids[0].Trim()].Intersect(rectangles[ids[1].Trim()].r)); } }