#include <bits/stdc++.h>
using namespace std;
struct TrieNode {
bool we;
TrieNode *child[26];
TrieNode(){
we=false;
for(int i=0;i<26;i++) { child[i] = nullptr; }
}
};
void insert(TrieNode* root, string str) {
TrieNode* curr = root;
for(char c : str) {
if(curr->child[c-'a'] == nullptr) {
TrieNode* nn = new TrieNode();
curr->child[c-'a'] = nn;
}
curr = curr->child[c-'a'];
}
curr->we = 1;
// cout<<"Insertion Done"<<endl;
}
bool search(TrieNode *root, string str) {
TrieNode *curr = root;
for(char ch : str) {
if(curr->child[ch-'a'] == nullptr) return false;
curr = curr->child[ch-'a'];
}
return curr->we;
}
int main() {
TrieNode* root = new TrieNode();
vector<string> keys = {"and","ant","do","dose"};
for(auto word : keys) {
insert(root, word);
}
cout<< search(root,"bose")<<endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpzdHJ1Y3QgVHJpZU5vZGUgewoJYm9vbCB3ZTsKCVRyaWVOb2RlICpjaGlsZFsyNl07CglUcmllTm9kZSgpewoJCXdlPWZhbHNlOwoJCWZvcihpbnQgaT0wO2k8MjY7aSsrKSB7IGNoaWxkW2ldID0gbnVsbHB0cjsgfQoJfQp9OwoKdm9pZCBpbnNlcnQoVHJpZU5vZGUqIHJvb3QsIHN0cmluZyBzdHIpIHsKCVRyaWVOb2RlKiBjdXJyID0gcm9vdDsKCWZvcihjaGFyIGMgOiBzdHIpIHsKCQlpZihjdXJyLT5jaGlsZFtjLSdhJ10gPT0gbnVsbHB0cikgewoJCQlUcmllTm9kZSogbm4gPSBuZXcgVHJpZU5vZGUoKTsKCQkJY3Vyci0+Y2hpbGRbYy0nYSddID0gbm47CgkJfQoJCWN1cnIgPSBjdXJyLT5jaGlsZFtjLSdhJ107Cgl9CgljdXJyLT53ZSA9IDE7CgkvLyBjb3V0PDwiSW5zZXJ0aW9uIERvbmUiPDxlbmRsOwp9Cgpib29sIHNlYXJjaChUcmllTm9kZSAqc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