Zipf's Law
Time limit1sMemory limit128 MB
For each test case, count the words in a book body and print the words that appear exactly n times, in lowercase alphabetical order.
- Level
Easy3 of 10
- Topics
- Hash map, String, Sorting, Implementation
- Solved
- No attempts yet
Problem
The Harvard linguist George Kingsley Zipf (1902–1950) discovered that, in a given book, the frequency of the -th most common word is proportional to .
Given the body of an English book, write a program that finds every word that appears exactly times. A word is a maximal sequence of letters, and words are separated by non-letter characters. Matching is case-insensitive, and every word in the text is a valid English word.
Input
The input consists of several test cases. The first line of each test case contains an integer . Everything from the next line up to (but not including) the line that reads EndOfText is the body of the book. The body contains at most 10000 words. EndOfText is only a marker that separates test cases and never appears within the body.
Output
For each test case, print every word that appears exactly times, in alphabetical order, one per line, in lowercase. If there is no such word, print There is no such word.
Print one blank line between consecutive test cases.