E-Mail Snooping
Time limit1sMemory limit128 MB
Count how many listed keywords appear as whole words in the email and raise an alarm when the count reaches the threshold.
Problem
An intelligence agency stores far more e-mail than any team of people could read, so the first pass is done by a program. Here you write a very simple version of that first pass.
Assume every e-mail consists only of words made up of lowercase letters, together with commas, periods, and whitespace (space, tab, newline). A word is a maximal run of lowercase letters. The agency keeps a list of keywords that raise alarms. If at least a certain number of distinct keywords from that list occur in the text, each at least once, the e-mail raises an alarm.
Write a program that determines which e-mails raise alarms.
Input
The first line is the number of data sets, followed by the data sets, each of the following form.
The first line contains three integers , , , separated by spaces. is the number of words that raise alarms, is the number of lines in the e-mail that follows, and is the number of keywords that need to occur to raise an alarm.
This is followed by lines, each containing a word of at most 20 lowercase letters and no other characters. Next come lines, each containing at most 80 characters, a mix of lowercase letters, commas, periods, and different forms of spaces. No word breaks across lines: a newline character ends a word, and a new word starts on the next line. Only exact matches count, so contest and contests do not match.
Output
For each data set, print Data Set x: on a line by itself, where is the number of the data set, starting at 1. On the next line print Alarm if the number of distinct keywords found in the e-mail is at least , and No Alarm otherwise. Print an empty line after each data set.