#include<algorithm> #include<cstdio> #include<cstring> #include<iostream> #define MAX 100005 usingnamespacestd; structTRIE { int son[26]; int num; }; TRIE trie[MAX]; string str; int tot; inlinevoidbuild_trie(){ int position = 0; for (int i = 0; i < str.length(); i++) { if (!trie[position].son[str[i] - 'a']) trie[position].son[str[i] - 'a'] = ++tot; position = trie[position].son[str[i] - 'a']; trie[position].num++; } }
inlineintget_ans(){ int position = 0; for (int i = 0; i < str.length(); i++) { if (!trie[position].son[str[i] - 'a']) return0; position = trie[position].son[str[i] - 'a']; } return trie[position].num; } intmain(int argc, charconst *argv[]){ /* code */ ios::sync_with_stdio(false); cin.tie(NULL); while (getline(cin, str) && str[0] != '\0') build_trie(); while (cin >> str) cout << get_ans() << "\n"; return0; }