#B4267. Sort and Count Words by Line

    ID: 11924 Type: Default 1000ms 256MiB

Sort and Count Words by Line

Sort and Count Words by Line

You are given a piece of text consisting of at most \(200\) lines. Each line contains up to \(200\) words, and each word has a maximum length of \(20\) characters. A word is defined as a sequence of non-whitespace characters.

Your task is to process each line by counting the number of words and then output the words sorted in ascending lexicographical order. For each line, output the count followed by the sorted words, all separated by a single space.

For example, if a line is:

banana apple cherry

The sorted order is: apple banana cherry and the output should be:

3 apple banana cherry

inputFormat

The input consists of multiple lines. There are at most 200 lines. Each line contains a series of words separated by whitespace. Each line has no more than 200 words, and each word is no longer than 20 characters.

outputFormat

For each input line, print a line that begins with the number of words in that line, followed by the words sorted in ascending lexicographical order. All values on the same line should be separated by a single space.

sample

banana apple cherry
3 apple banana cherry