#C114. Count Distinct Banned Words

    ID: 40711 Type: Default 1000ms 256MiB

Count Distinct Banned Words

Count Distinct Banned Words

Given an essay text and a list of banned keywords, count the number of distinct banned words present in the essay. The comparison is case-insensitive and punctuation should be ignored. For example, if the essay is "The quick brown fox jumps over the laZy Dog. The fox is very keen and agile." and the banned list is "fox dog rabbit", then the output should be "2 banned words found.".

Note: Only whole words matching (after removing punctuation) should be counted. If exactly one banned word is found, output: 1 banned word found. Otherwise, output the count followed by the phrase banned words found.

The problem can be mathematically modeled as follows:

Let \(E\) be the essay string and \(B = \{b_1,b_2,\dots,b_k\}\) be the set of banned words (all in lowercase). Define the set of words \(W\) extracted from \(E\) by first converting \(E\) to lowercase and removing non-alphabet characters from each word, then counting the unique words in \(W \cap B\). The output is then determined by the cardinality \(|W \cap B|\).

inputFormat

The input is provided via standard input (stdin) and consists of two lines:

  • The first line contains the essay text, which may include spaces and punctuation.
  • The second line contains a list of banned words separated by a single space.

Please note that the essay text may be very long and contain various punctuation marks.

outputFormat

Output a single line to standard output (stdout). The output is a message indicating the number of distinct banned words found in the essay. The message should be formatted as follows:

  • If exactly one banned word is found, output: 1 banned word found.
  • Otherwise, output: <n> banned words found. where <n> is the count of distinct banned words.
## sample
The quick brown fox jumps over the laZy Dog. The fox is very keen and agile.
fox dog rabbit
2 banned words found.