Hide

Problem B
Sideways Sorting

We are so accustomed to reading strings from left to right, it can be a little difficult to think of strings that go right to left or even vertically. Here’s your chance to get some practice.

Input

Input consists of up to $100$ test cases. Each test case starts with a line containing a pair of integers, $1 \le r, c \le 15$. This is followed by $r$ lines each containing $c$ characters chosen from A–Z (lowercase and uppercase). The last test case is followed by values of $0$ for both $r$ and $c$.

Output

For each test case, print out a block of text containing the same columns as the input block but in sorted order. Think of each column as a string reading from top to bottom. Your output block should have the columns sorted lexicographically from left to right. Your sort should be a stable sort and it should ignore case. Print a blank line between each pair of adjacent output blocks.

Sample Input 1 Sample Output 1
3 3
oTs
nwi
eox
3 4
xAxa
yByb
zCyc
0 0
osT
niw
exo

Aaxx
Bbyy
Ccyz

Please log in to submit a solution to this problem

Log in