#C14034. Summarize Large Text File
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 worldThe 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:
- The first line contains the total word count (an integer).
- 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. - 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.
Hello world
Hello
world world
5
Hello:2 world:3
world:3 Hello:2
</p>