Woburn Challenge 1996
To represent an 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 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 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,
AABB
which becomes2A2B
. In the 2nd column we getB2AB
and so on... Note that we have dropped the 1s from1B2A1B
and assumed there is only one occurrence if there is no number preceding the letter. Thus compression by this method gives2A2BB2ABB2ACBA2CB3C
.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: , the number of rows and , the number of columns.
Input Specification
In the data file, there are 5 data sets. The first line of each data set will contain and , the height and width of the table. Both and will be integers from 1 to 10. The second line of each data set will contain a column-compressed representation of the table.
Output Specification
For each data set, output the row-compressed representation of the table.
Sample Input
4 5
2A2BB2ABB2ACBA2CB3C
3 3
3W3W3W
(and 3 more data sets)
Sample Output
A4B4ACB2A2C2B3C
3W3W3W
Comments