Hurricane Warning
InterviewTime limit1sMemory limit1024 MB
For each data set, count the people whose consumed media string shares at least one letter with the media string the authorities use for the warning.
- Level
Easy2 of 10
- Topics
- String, Implementation
- Solved
- No attempts yet
Problem
Before a hurricane arrives, it is very important to warn as many people as possible who are on or near its path. With a warning, people can move to a safer place, reinforce their homes, and, if they must stay, stock up on essentials and install backup power systems. The question is how to reach as many people as possible. If announcements are made only on TV, people who do not watch TV may miss the warnings and instructions. You are given which media each person consumes and which media the authorities use for warnings. Determine how many people receive the warning.
Encoding
The information is encoded as strings of letters. Each letter stands for one type of media: 'T' for TV, 'F' for Fakebook, and 'X' for ex-Twitter. A person is informed if the string for the media used and the string for the media consumed share at least one letter. Otherwise, the person is not informed.
Input
The first line contains K (1 ≤ K ≤ 100), the number of data sets. Each data set has the following form.
The first line of a data set contains an integer n (0 ≤ n ≤ 10000), the number of people considered.
The next line is a string of 1 to 10 uppercase letters, describing the media used to announce the hurricane. No other symbols occur.
This is followed by n lines, each with a string of 1 to 10 uppercase letters, describing the media consumed by person i. No other symbols occur.
Output
For each data set, first output 'Data Set x:' on a line by itself, where x is the data set number. Then output the number of people who received the hurricane warning through at least one type of media.
Follow each data set with a blank line.