You are given a set of \(N\) line segments that are either horizontal or vertical. Write a program to determine the points of intersection of all the horizontal line segments with the vertical line segments.
Note: Do not consider the coincident endpoints as intersections.
Input format
- First line: \(N\)
- Next \(N\) lines: Four space-separated integers, \(x1\), \(y1\), \(x2\), and \(y2\) denoting the coordinates of two line segments
Output format
Sort and print all the intersection points of the horizontal and the vertical line segments. The intersection point is represented as \((x,\ y)\) with space between them.
Constraints
\(1 ≤ N ≤ 10^{3}\)
For horizontal line:
\(1 ≤ x1 < x2 ≤ 10^{6}\)
\(1 ≤ y1 = y2 ≤ 10^{6}\)
For vertical line:
\(1 ≤ x1 = x2 ≤ 10^{6}\)
\(1 ≤ y1 < y2 ≤ 10^{6}\)
3 1 2 4 2 2 1 2 3 3 1 3 3
2 2 3 2
The intersections are (2,2) and (3,2)
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor