#C14034. Summarize Large Text File

    ID: 43639 Type: Default 1000ms 256MiB

Summarize Large Text File

Summarize Large Text File

You are given the contents of a large text file via standard input. Your task is to summarize the file by computing:

  • The total word count.
  • The frequency of each word. Print these word-frequency pairs in lexicographical order (i.e. dictionary order) with the format word:count.
  • The top 10 most common words sorted primarily by descending frequency and, in case of ties, by lexicographical order. Print these pairs using the same format.

For example, given the file content:

Hello world
Hello
world world
The total word count is \(5\), the word frequency (in lexicographical order) is Hello:2 world:3, and the top 10 words are world:3 Hello:2.

Note: All formulas (if any) must be written in LaTeX format (e.g. \(\dots\)).

inputFormat

The input is provided via standard input.

It consists of the entire content of a text file spread over multiple lines. Words are separated by whitespace.

outputFormat

The output should have three lines:

  1. The first line contains the total word count (an integer).
  2. The second line contains the frequency of each word in lexicographical order. Each pair is formatted as word:count and pairs are separated by a single space. If there are no words, output an empty line.
  3. The third line contains the top 10 most common words, sorted by descending frequency (and by lexicographical order in case of ties), formatted in the same way. If there are no words, output an empty line.
## sample
Hello world
Hello
world world
5

Hello:2 world:3 world:3 Hello:2

</p>