#K77897. Analyzing the Relationship Between Rectangles
Analyzing the Relationship Between Rectangles
Analyzing the Relationship Between Rectangles
You are given two axis-aligned rectangles defined by the coordinates of their top-left and bottom-right corners. For each pair of rectangles, determine the relationship between them according to the following rules:
- If the two rectangles are identical (i.e. all corresponding coordinates are equal), output (i).
- If the first rectangle is completely inside the second rectangle, output (r1_ins_r2).
- If the second rectangle is completely inside the first rectangle, output (r2_ins_r1).
- If the rectangles do not overlap at all, output (n).
- Otherwise, if they partially overlap, output (o).
Each test case is provided on a separate line containing eight integers: the first four describe the first rectangle and the next four describe the second rectangle. The sequence of test cases is terminated by a line with eight zeros (which should not be processed).
For example, given the input:
1 4 5 1 1 4 5 1 0 0 0 0 0 0 0 0
The output would be:
i
inputFormat
Input is read from standard input (stdin). Each test case is given on a single line containing eight space-separated integers. These integers represent two rectangles: the first rectangle is defined by its top-left ((x_1, y_1)) and bottom-right ((x_2, y_2)) coordinates, and the second rectangle by ((x_3, y3)) and ((x_4, y_4)) respectively. The input terminates with a line containing eight zeros.
outputFormat
For each test case (except the terminating one), output a single line to standard output (stdout) containing one of the following strings that represents the relationship between the two rectangles:
- "i" if the rectangles are identical.
- "r1_ins_r2" if the first rectangle is entirely inside the second rectangle.
- "r2_ins_r1" if the second rectangle is entirely inside the first rectangle.
- "n" if the rectangles do not overlap at all.
- "o" if the rectangles partially overlap.## sample
1 4 5 1 1 4 5 1
0 0 0 0 0 0 0 0
i
</p>