#K15676. Word Frequency in Paragraphs
Word Frequency in Paragraphs
Word Frequency in Paragraphs
You are given (T) paragraphs. For each paragraph, determine the frequency of each word and output the result in lexicographical order. In other words, for every paragraph, list each unique word along with its frequency, where each line corresponds to a word followed by its count separated by a space. Use the following format for each paragraph's result:
word count
If a paragraph is empty, output a blank line. Different paragraphs’ results should be separated by a newline.
The formula for the output is given by: [ \text{For each word } w: \quad w \quad \text{count}(w) ]
inputFormat
The input is read from standard input. The first line contains a single integer (T) indicating the number of paragraphs. This is followed by (T) lines, each representing a paragraph which may contain multiple words separated by spaces.
outputFormat
For each paragraph, output the frequency of each word in lexicographical order. Each output line must display a word followed by its frequency (separated by a single space). If there are multiple paragraphs, each paragraph's result should be printed sequentially and separated by a newline. For an empty paragraph, output a blank line.## sample
1
the quick brown fox jumps over the lazy dog
brown 1
dog 1
fox 1
jumps 1
lazy 1
over 1
quick 1
the 2
</p>