#C3576. Rotated Pattern Display

    ID: 47018 Type: Default 1000ms 256MiB

Rotated Pattern Display

Rotated Pattern Display

You are given one or more binary patterns. For each pattern, you will be given its dimensions followed by the pattern itself. Your task is to rotate the pattern by 90° clockwise and then display both the original and rotated patterns side by side, row by row.

More formally, for a given matrix \(A\) of size \(M \times N\), its rotated version \(B\) is defined as:

[ B[j][M-1-i] = A[i][j]\quad \text{for } 0 \le i < M, ; 0 \le j < N. ]

After computing the rotated pattern, display the rows of the original matrix and the corresponding row of the rotated matrix separated by a single space. If the rotated matrix has more rows than the original, only display as many rows as the original has.

Input processing stops when a line with "0 0" is encountered.

inputFormat

The input consists of multiple test cases. For each test case:

  • The first line contains two integers \(M\) and \(N\) representing the number of rows and columns of the pattern.
  • The next \(M\) lines each contain \(N\) integers (either 0 or 1) separated by spaces.

The input terminates with a line containing "0 0".

outputFormat

For each test case, print the original pattern and the rotated pattern side by side. For each row of the original pattern, print the row from the original matrix followed by a space and then the corresponding row from the rotated matrix.

Separate outputs for different test cases by an empty line.

## sample
3 3
1 0 1
0 1 0
1 0 1
2 4
1 0 0 1
0 1 1 0
0 0
1 0 1 1 0 1

0 1 0 0 1 0 1 0 1 1 0 1

1 0 0 1 0 1 0 1 1 0 1 0

</p>