ZOJ Problem Set - 1077
Statement of the Problem
The population of the small village of Zombiniville is famous fir its genetic characteristics. The inhabitants present only 5 variations on 4 aspects (hair, eyes, nose and feet). Two research companies, Gentec and Genco, tabulated an extensive series of data on the inhabitants of Zombiniville.
Both companies used symbols for the 4 aspects and its variations. Gentec used the groups (A, B, C, D, E), (F, G, H, I, J), (K, L, M, N, O) and (P, Q, R, S, T), which Genco used (a, b, c, d, e), (f, g, h, i, j), (k, l ,m, n, o) and (p, q, r, s, t), but not necessarily for the same group or in the same order inside a group. For example, the group (A, B, C, D, E) from Gentec could correspond to (r, p, t, s, q) from Genco. In other words, "A" corresponds to "r", "B" corresponds to "p", "C" to "t", "D" to "s" and "E" to "q".
Recently the two companies reached an agreement and decided to exchange their research results. However, a group of international activists against human genetic research invaded the offices of the two companies and destroyed part of the reports - exactly the interpretation of the codes.
You and your team were hired to develop a program to establish a relationship
among the two notations. As the companies don't want to waste its capital at
random, they prepared a battery of tests for your program, before buying it.
Each test case has the following data:
1. A line with n, the number of individuals in the test case. You can assume
that 0 < n < 64.
After a test case, a new one begins. The end of test cases is indicated by n = 0.
You can assume that the test cases are well formed. There are no errors in
the input data.
For each test case, an association table should be supplied, as in the example
below. Note that the pairs are printed in alphabetical order of the capital
letters, five per line. Obviously, Gentec and Genco are testing your program,
and they don't supply their real data. You can assume that the association table
is changed between test cases. You should print only the associations that are
unequivocally determined. If there are two or more possibilities for a given
letter, you should print a question mark after this letter.
Source: South America 2001