Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bits/stdc++.h"
- #include "vector"
- using namespace std;
- const int N = 2e6 + 5;
- typedef struct st{
- st *h[26];
- }node;
- node * get(){
- node *temp = new node;
- for(int i = 0; i < 26; i++)
- temp->h[i] = NULL;
- return temp;
- }
- void insert(node *head, string s){
- node *temp;
- if(!head->h[s[0]-'a']){
- head->h[s[0]-'a'] = get();
- }
- temp = head->h[s[0]-'a'];
- for(int i = 1; i < s.size(); i++){
- if(!temp->h[s[i]-'a']){
- temp->h[s[i]-'a'] = get();
- }
- temp = temp->h[s[i]-'a'];
- }
- }
- bool search(node *head, string s){
- node * temp = head;
- for(int i = 0; i < s.size(); i++){
- if(!temp->h[s[i]-'a'])return false;
- temp = temp->h[s[i]-'a'];
- }
- return true;
- }
- int main(){
- node *head = get();
- int n;string s;
- cin >> n;
- while(n--){
- cin >> s;
- insert(head, s);
- }
- int q;
- cin >> q;
- while(q--){
- cin >> s;
- cout << search(head, s) << '\n';
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment