Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- const int MAX=1e5+9;
- string h;
- struct trie
- {
- trie * child [27];
- bool ischild[27];
- int here=0;
- bool endf=0;
- };
- trie head;
- void enter(string &h)
- {
- trie * temp= &head;
- for( int i=0;i<h.size();i++)
- {
- //cout<<i<<endl;
- if(!temp->ischild[h[i]-'a'])temp->child[h[i]-'a']=new trie;
- temp->ischild[h[i]-'a']=1;
- temp=temp->child[h[i]-'a'];
- temp->here++;
- if(i==(int)h.size()-1)temp->endf=1;
- }
- }
- bool srch(string & h)
- {
- trie * temp= &head;
- for( int i=0;i<h.size();i++)
- {
- // cout<<i<<endl;
- if(!temp->ischild[h[i]-'a'])return 0;
- temp=temp->child[h[i]-'a'];
- if(i==(int)h.size()-1)return temp->endf;
- }
- }
- int pref(string &h)
- {
- trie * temp= &head;
- for( int i=0;i<h.size();i++)
- {
- // cout<<i<<endl;
- if(!temp->ischild[h[i]-'a'])return 0;
- temp=temp->child[h[i]-'a'];
- if(i==(int)h.size()-1)return temp->here;
- }
- }
- int main()
- {
- for(int i=0;i<5;i++)
- {
- cin>>h;
- enter(h);
- }
- string c;
- cin>>c;
- cout<<pref(c);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement