#C12666. Word Frequency Counter
Word Frequency Counter
Word Frequency Counter
You are given a list of text strings and a flag indicating whether to ignore common English stop words. Your task is to count the frequency of each unique word (case-insensitive) after removing punctuation, and then output each word along with its frequency count. When the flag is set to true
, ignore the stop words. The list of stop words is given as \( \{ \text{the, is, in, and, or, an, a, of, to, it, that, on, for, with, as, by, at, from} \} \).
Words should be normalized to lowercase and punctuation removed. Finally, output the results by printing each unique word and its frequency on a separate line, sorted in lexicographical order by the word.
Note: If the flag is false
, include all words in the count.
inputFormat
The input is read from the standard input (stdin) and has the following format:
- The first line contains a boolean value (
true
orfalse
) indicating whether to ignore the stop words. - The second line contains an integer n, which indicates the number of text lines to follow.
- The next n lines each contain a string, which can be a word or a sentence.
outputFormat
Print the frequency count of each valid word to the standard output (stdout). Each line should contain a word and its count separated by a space. The lines must be sorted in lexicographical (alphabetical) order by the word.
## sampletrue
2
Hello
world hello
hello 2
world 1
</p>