#C14743. Word Frequency Analysis

    ID: 44426 Type: Default 1000ms 256MiB

Word Frequency Analysis

Word Frequency Analysis

You are given a block of text via standard input. Your task is to perform text analysis by doing the following:

  • Remove all punctuation and convert the text to lowercase.
  • Count the frequency of each word, ignoring the following common stopwords: \(\{\text{and}, \text{the}, \text{is}, \text{in}, \text{at}\}\).
  • Sort the words primarily in descending order by frequency and in case of ties, sort them in lexicographical (alphabetical) order in ascending order.

Finally, print the top 10 most frequent words (or all words if there are fewer than 10) with each word and its frequency on a separate line in the format:

\[ \texttt{word: count} \]

For example, if the cleaned text is "hello world hello world", the frequency count is \(\{ hello: 2, world: 2 \}\). After sorting (tie broken alphabetically), the output should be:

hello: 2
world: 2

inputFormat

The input consists of a block of text provided via standard input. The text can span multiple lines. You should read the entire input until EOF.

outputFormat

Output the top 10 most frequent words (or all words if fewer than 10) in separate lines. Each line should be in the format "word: count". The words must be sorted primarily in descending order of frequency and secondarily in ascending lexicographical order if frequencies are equal.

## sample
Hello, World! Hello, world.
hello: 2

world: 2

</p>