Frequency analysis of words in a text
Go
Medium
maps
Task «Frequency analysis of words in a text»
Write a program that reads text from multiple lines, counts the frequency of each word (case-insensitive), and outputs the word and its frequency in descending order of frequency. If the frequencies are equal, the words are output in lexicographic order. A word is considered a sequence of letters (Cyrillic and Latin), separated by spaces, punctuation marks, and line break characters. Ignore punctuation marks and digits.
Input Format
The input consists of several lines of text (up to 1000 lines, each line up to 1000 characters). Lines may contain spaces, punctuation marks, digits, and letters.
Output Format
Output each unique word and its frequency in the format 'word: frequency', one per line, sorted by descending frequency, and in case of a tie — by ascending word (lexicographically).
Examples
Example 1
INPUT
Hello world! Hello everyone.
OUTPUT
hello: 2
everyone: 1
world: 1
Example 2
INPUT
Go is awesome. Go is fast.
OUTPUT
go: 2
is: 2
aweSome: 1
fast: 1
Example 3
INPUT
Привет, мир! Привет всем.
OUTPUT
привет: 2
всем: 1
мир: 1
main.go