INPUT FILE: compress.in
OUTPUT FILE: compress.out
To represent an m by n table of capital letters such as
A | B | B | B | B |
A | A | A | A | C |
B | A | A | C | C |
B | B | C | C | C |
in a text file we could either type out all (m*n) characters or figure out some way to compress the data to a smaller size. Two ways we could do this are:
Column Compression
We could go down each column, left to right, and for consecutive repeated
characters within a column replace them by a single occurence of that character
preceded by a number indicating how many of that character there are. For this
example we have, in the first column, AABB which becomes 2A2B. In the 2nd column
we get B2AB and so on... Note that we have dropped the 1s from 1B2A1B and assumed
there is only one occurence if there is no number preceding the letter. Thus
compression by this method gives 2A2BB2ABB2ACBA2CB3C.
Row Compression
Likewise, we could compress each row going from left to right in the same
fashion to get A4B4ACB2A2C2B3C in the above example.
Your task is to convert a column compression into a row compression given the size of the table: m, the number of rows and n, the number of columns.
INPUT
In the data file there are 5 data sets.
The first line of each data set contains m and n, the height and width of the
table. Both m and n will be integers from 1 to 10.
The second line of each data set will contain a column-compressed representation
of the table.
OUTPUT
For each data set output the row-compressed representation of the table.
Sample Input File
4 5 2A2BB2ABB2ACBA2CB3C 3 3 3W3W3W
(and 3 more data sets)
Output for Sample Input
A4B4ACB2A2C2B3C 3W3W3W