import java.util.Scanner;

/**
 * Accepts a line of text as input and then displays each "word" vertically. A "word" is 
 * a maximal sequence of non-whitespace characters.
 *
 * @author Drue Coles
 */
public class Transposer {

    public static void main(String[] args) {
        System.out.print("Enter a line of text: ");
        Scanner in = new Scanner(System.in);
        String input = in.nextLine();
        String[] words = input.split(" ");
        int numberOfWords = words.length;        

        // find length of longest word in the list
        int max = 0;
        for (String word : words) {
            if (word.length() > max) {
                max = word.length();
            }
        }

        // Fill a two-dimensional array of characters with the input:
        // c[i][j] is the jth character of the ith string.
        char[][] c = new char[numberOfWords][max];
        for (int i = 0; i < numberOfWords; i++) {
            for (int j = 0; j < max; j++) {
                if (words[i].length() > j) {
                    c[i][j] = words[i].charAt(j);
                } else {
                    c[i][j] = ' ';
                }
            }
        }

        // Print out the characters column by column.
        for (int i = 0; i < max; i++) {
            for (int j = 0; j < numberOfWords; j++) {
                System.out.print(c[j][i] + " ");
            }
            System.out.println();
        }
    }
}