Signboard
InterviewTime limit1sMemory limit256 MB
Count how many of the given strings contain the store name as an equally spaced subsequence, where each string counts at most once.
- Level
Medium4 of 10
- Topics
- String, Brute force, Implementation
- Solved
- No attempts yet
Problem
Someone opened a new convenience store near a school. A store's face is its signboard, and because this store is not part of a franchise, the owner has to pay for and build the signboard himself.
To save money, he decides to reuse the old signboards that the previous owner left behind. From a single old signboard he wants to erase some characters so that the remaining string is exactly the store's name. The catch is that the remaining characters must all be equally spaced: there must be some starting position and a fixed step such that reading the character at that position and every -th position afterward spells the store's name.
A new signboard must be made from a single old signboard; it cannot be cut or glued together. Even if one old signboard can produce the name in several different ways, it still counts as only one usable signboard.
Given the store's name and the old signboards, write a program that counts how many new signboards can be made.
Input
The first line contains the number of old signboards ().
The second line contains the store's name, consisting only of lowercase letters, with length between 3 and 25 inclusive.
Each of the next lines contains the string written on one old signboard. Each string consists only of lowercase letters and has length between 1 and 100 inclusive.
Output
Print the number of new signboards that can be made.
Hint
Suppose the store's name is bar.
- On the first signboard
abracadabra, keeping only the 2nd, 6th, and 10th characters (step 4) spellsbar. - On the second signboard
bear, erasing the 2nd character leavesbar, but the remaining characters are not equally spaced. - The third signboard
barcan be used as is. - On the fourth signboard
baraxbara, keeping the 1st, 2nd, and 3rd characters, or the 6th, 7th, and 8th characters, spellsbar.
So new signboards can be made from the first, third, and fourth signboards, and the answer is 3.