#K12531. Counting Matching Subsequences
Counting Matching Subsequences
Counting Matching Subsequences
You are given a string \(s\) and a list of \(n\) words. A word is considered a subsequence of \(s\) if it can be derived from \(s\) by deleting some characters (possibly none) without changing the relative order of the remaining characters. Your task is to count how many words in the list are subsequences of \(s\).
Example:
Input: s = "abcde" words = ["a", "bb", "acd", "ace"] Output: 3 Explanation: "a", "acd", and "ace" are subsequences of "abcde".
Note: A subsequence of a string \(s\) is defined as a new string generated from \(s\) by deleting some (or no) characters without changing the order of the remaining characters.
inputFormat
The input is given via standard input and has the following format:
- The first line contains the string \(s\).
- The second line contains an integer \(n\) representing the number of words.
- The next \(n\) lines each contain a word from the list.
It is guaranteed that \(0 \leq |s|, |word| \leq 10^5\) and \(n\) is at least 1.
outputFormat
Output a single integer on standard output representing the number of words from the list that are subsequences of \(s\).
## sampleabcde
4
a
bb
acd
ace
3