#C8280. Pipe System Description Comparison
Pipe System Description Comparison
Pipe System Description Comparison
You are given descriptions of pipe systems. Each description is provided as a string where the first token is a number (which can be considered an identifier) followed by a series of tokens. The tokens include integers and direction commands: N, E, S, and W. Two pipe system descriptions are considered equivalent if, after applying any rotation (by 90° increments) to the directional commands, their normalized forms are identical. In other words, the order of commands may be rotated, but if the two descriptions represent the same system under some rotation, they are considered identical.
Your task is to compare pairs of pipe system descriptions. For each pair, output Identical
if the descriptions represent the same pipe system and Different
otherwise.
The input will consist of multiple lines. Each two consecutive non-zero lines (except the terminating line) form a test pair. A line containing only 0
signals the end of input.
Note: The rotation means converting directions as follows:
[ \begin{aligned} N &\to E\ E &\to S\ S &\to W\ W &\to N \end{aligned} ]
inputFormat
The input is read from standard input and consists of several lines. Each pipe system description is represented on a separate line. Descriptions are given in pairs (the first two lines form the first pair, the next two lines form the second pair, etc.). The input terminates with a line containing only 0
.
For example:
12 1 N 1 E 2 S 2 W 12 1 N 1 E 2 S 2 W 0
outputFormat
For each pair of pipe system descriptions, output a single line containing Identical
if the two descriptions represent the same pipe system (possibly after rotation), or Different
otherwise. The outputs should be in the same order as the input pairs.
For example, the output corresponding to the above input is:
Identical## sample
12 1 N 1 E 2 S 2 W
12 1 N 1 E 2 S 2 W
0
Identical
</p>