#C14456. Reverse Words and Count

    ID: 44107 Type: Default 1000ms 256MiB

Reverse Words and Count

Reverse Words and Count

Given a string, reverse the order of its words and count the number of words. Extra spaces should be ignored. For example, if the input is "The quick brown fox jumps over the lazy dog", then the expected output is dog lazy the over jumps fox brown quick The on the first line and 9 on the next line, because there are 9 words.

Note: The problem requires handling of leading, trailing, and multiple spaces between words. The splitting of words is based on whitespace, and the output must use a single space to separate the reversed words. Use the following formula to denote the number of words when given a word array \(W\):

\( \text{count} = |W| \)

inputFormat

The input consists of a single line containing the string to be processed. The input may contain extra spaces at the beginning, in between, or at the end.

outputFormat

The output should contain two lines. The first line is the string with the words in reverse order separated by a single space, and the second line is an integer representing the number of words.

## sample
The quick brown fox jumps over the lazy dog
dog lazy the over jumps fox brown quick The

9

</p>