[题目链接](http://hihocoder.com/problemset/problem/1014)
#include <iostream>
#include <string>
using namespace std;
struct trie{
char key;
int num;
trie *next[26];
trie(){
num = 0;
for(int i = 0; i < 26; i++) next[i] = NULL;
}
};
trie root;
void ins(string s) {
trie *head = &root;
for(int i = 0; i < s.size(); i++) {
int k = s[i] - 'a';
if(head->next[k] == NULL) {
trie *node = new trie;
node->key = s[i];
head->next[k] = node;
}
head = head->next[k];
head->num++;
}
}
int ser(string s) {
trie *head = &root;
for(int i = 0; i < s.size(); i++) {
int k = s[i] - 'a';
if(head->next[k] == NULL ) return 0;
else {
head = head->next[k];
}
}
return head->num;
}
int main(){
string s;
int n,m;
cin >> n;
while(n--) {
cin >> s;
ins(s);
}
cin >> m;
while(m--) {
cin >> s;
cout << ser(s) << endl;
}
return 0;
}