#K56017. Phrase Frequency Counter

    ID: 30105 Type: Default 1000ms 256MiB

Phrase Frequency Counter

Phrase Frequency Counter

You are given a list of sentences. Your task is to count the frequency of each unique word across all the sentences. A word is defined by consecutive non-space characters, and the sentences are split using whitespace as the delimiter.

The output should display each word alongside its frequency in the order of their first appearance in the input. For example, if the input sentences are:

Hello world
world of coding
Hello world of

then the output should be:

Hello 2
world 3
of 2
coding 1

Note: The input is read from standard input (stdin) and the output should be written to standard output (stdout).

inputFormat

The first line contains an integer T representing the number of sentences. Each of the next T lines contains one sentence.

For example:

3
Hello world
world of coding
Hello world of

outputFormat

For each word, output a line containing the word followed by a space and its frequency. The words must appear in the order they first appear in the input.

For example, the output for the above input should be:

Hello 2
world 3
of 2
coding 1
## sample
3
Hello world
world of coding
Hello world of
Hello 2

world 3 of 2 coding 1

</p>