#C12165. Word Frequency Counter

    ID: 41562 Type: Default 1000ms 256MiB

Word Frequency Counter

Word Frequency Counter

You are given a sentence. Your task is to count the frequency of each word in the sentence while ignoring case differences and punctuation. The words should be output in alphabetical order along with their counts. For example, if the input is "Hello, World!", the output should be:

hello: 1
world: 1


Note that punctuation should be removed, and all letters should be treated as lowercase.

The problem can be summarized by the following steps:

  • Convert the entire sentence to lowercase.
  • Remove all punctuation characters. (In LaTeX, the set of punctuation symbols is not expressed as a formula but rather handled by the program logic.)
  • Split the sentence into words using whitespace as the delimiter.
  • Count the occurrences of each word.
  • Print each word along with its frequency in alphabetical order, each on a new line.

inputFormat

The input consists of a single line containing a sentence. The sentence may include punctuation and a mix of uppercase and lowercase letters.

outputFormat

For each distinct word in the sentence, output a line in the format "word: count". The words must be in alphabetical order. If the input is empty, produce no output.## sample

Hello World
hello: 1

world: 1

</p>