structNode { int L = 1; char ch = ' '; vector<Node*> successors;
Node(char c) { ch = c; } };
classTrie { private: Node* root;
voidupdatePrefix(Node* node, string word, int idx){ if (idx == word.size()) return;
bool find = false; for (int i = 0; i < node->successors.size(); i++) { if (node->successors[i]->ch == word[idx]) { find = true; node->successors[i]->L++; updatePrefix(node->successors[i], word, idx + 1); break; } }
if (!find) { for (int i = idx; i < word.size(); i++) { node->successors.push_back(newNode(word[i])); node = node->successors.back(); } } }
intfindPrefix(Node* node, string query, int idx){ for (int i = 0; i < node->successors.size(); i++) { if (node->successors[i]->ch == query[idx]) { if (idx == query.size() - 1) return node->successors[i]->L;
intmain(){ int n = 0; cin >> n; string* words = new string[n]; for (int i = 0; i < n; i++) cin >> words[i]; int m = 0; cin >> m; string* queries = new string[m]; for (int i = 0; i < m; i++) cin >> queries[i];
Trie trie; for (int i = 0; i < n; i++) trie.insert(words[i]);
for (int i = 0; i < m; i++) cout << trie.getStat(queries[i]) << endl;