Your task is to use the TRIE data structure and search the given string A. If found print 1 else 0. |
Trie is an efficient information retrieval data structure. Use this data structure to store Strings and search strings. Your task is to use the TRIE data structure and search the given string A. If found print 1 else 0.
Print the respective output in the respective line.
Example:
Input:
1
8
the a there answer any by bye their
the
Output:
1
#include <bits/stdc++.h>
using namespace std;
int main() {
//code
int t;
cin>>t;
while(t--)
{
string s;
int n;
cin>>n;
vector<string> v;
for(int i=0;i<n;++i)
{
cin>>s;
v.push_back(s);
}
cin>>s;
if(find(v.begin(),v.end(),s)!=v.end())
cout<<1<<endl;
else
cout<<0<<endl;
}
return 0;
}