Finding Rectangles

Consider the point sets in figures 1a, 2a, and 3a. Using only those points as vertices, figures 1b, 2b, and 3b show all the rectangles that can be formed with horizontal and vertical sides. No rectangles can be formed from the points in figure 4. Your task is to write a program that can find all rectangles that can be formed from a given set of points. The example input and output given below correspond to the figures above. Input The input file contains one or more point sets, followed by a line containing the number ‘0’ that signals the end of the file. Each point set begins with a line containing n, the number of points, and is followed by n lines that describe the points. Each point description contains a capital letter that is the label of the point, then a space, the horizontal coordinate, a space, and the vertical coordinate. Within each set, points labels occur in alphabetical order. Note that since each point is labelled with a capital letter there can be at most 26 points. All coordinates are nonnegative integers less than 50. Points within a set are unique.

2/3 Output The output for each point set starts with ‘Point set ’, followed by the number of the point set and a colon. If there are no rectangles, ‘ No rectangles’ appears after the colon. If there are rectangles, they are listed starting on the next line. A blank precedes each rectangle. Each rectangle is given by its vertex labels, in clockwise order from the upper left, so the order is upper left, upper right, lower right, lower left. The rectangles are listed ten per line, except for the last line, where there may be as few as one. The rectangles are listed in alphabetical order. Sample Input 7 A11 B21 C31 D23 E33 F14 G34 8 B11 D21 F41 J44 L24 M23 N43 P12 12 A15 B25 C14 D24 E13 F23 G12 H22 I11 J21 K10 L20 5 B11 D21 L24 N23 P12 0 Sample Output Point set 1:

3/3 DECB FGCA Point set 2: LJFD LJNM MNFD Point set 3: ABDC ABFE ABHG ABJI ABLK CDFE CDHG CDJI CDLK EFHG EFJI EFLK GHJI GHLK IJLK Point set 4: No rectangles