#P2536. Virus Identification on Samuel Planet
Virus Identification on Samuel Planet
Virus Identification on Samuel Planet
Scientists on planet Samuel discovered a huge ice lake near its south pole, from which a robot collected many RNA fragments. After extensive research, scientists found that many of these RNA fragments belonged to unknown viruses. Each RNA fragment is a sequence of characters chosen from {A, C, T, G}. The scientists also summarized a virus template for Samuel Planet. A virus template is a pattern consisting of the letters A, C, T, G along with the wildcards *
and ?
. Here, the wildcard *
represents matching zero or more characters, and ?
represents matching exactly one character. Formally, if we denote the empty string by \(\varepsilon\), then:
*
can match \(\varepsilon\) or any string, i.e. any sequence of characters (\(\varepsilon, X, XX, XXX, \ldots\)).?
matches any single character from \(\{A, C, T, G\}\).
If an RNA fragment matches the virus template, then it is considered a virus. For example, given the virus template A*G?C
:
- RNA fragments
AGTC
andAGTGTC
are viruses. - RNA fragment
AGTGC
is not a virus.
Since the non-virus RNA fragments are extremely valuable for further research, your task is to help identify and count the RNA fragments that are not viruses.
inputFormat
The input consists of multiple lines:
- The first line contains a string representing the virus template pattern. The pattern consists of uppercase letters (A, C, T, G) and the wildcards '*' and '?'.
- The second line contains a positive integer \(n\), the number of RNA fragments.
- The following \(n\) lines each contain a string representing an RNA fragment (a sequence composed of A, C, T, G).
outputFormat
Output a single integer representing the number of RNA fragments that do not match the virus template pattern.
sample
A*G?C
3
AGTC
AGTGTC
AGTGC
1