Woburn Challenge 1996
To represent an ~m \times n~ table of capital letters such as
in a text file we could either type out all ~(m\times n)~ characters or figure out some way to compress the data to a smaller size. Two ways we could do this are:
We could go down each column, left to right, and for consecutive repeated characters within a column replace them by a single occurrence of that character preceded by a number indicating how many of that character there are. For this example we have, in the first column,
2A2B. In the 2nd column we get
B2ABand so on... Note that we have dropped the 1s from
1B2A1Band assumed there is only one occurrence if there is no number preceding the letter. Thus compression by this method gives
Likewise, we could compress each row going from left to right in the same fashion to get
A4B4ACB2A2C2B3Cin 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.
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.
For each data set output the row-compressed representation of the table.
4 5 2A2BB2ABB2ACBA2CB3C 3 3 3W3W3W
(and 3 more data sets)