| 33 | }; |
| 34 | |
| 35 | void insertTrie(TrieNode *root, string &s, int index){ |
| 36 | for (int i=0; i<s.size(); i++){ |
| 37 | if (root->alphabets[s[i]-'a']==NULL){ |
| 38 | root->alphabets[s[i]-'a']=new TrieNode(); |
| 39 | } |
| 40 | if (root->indexes.size()<5) root->indexes.push_back(index); |
| 41 | root=root->alphabets[s[i]-'a']; |
| 42 | } |
| 43 | if (root->indexes.size()<5) root->indexes.push_back(index); |
| 44 | root->endOfword=true; |
| 45 | } |
| 46 | |
| 47 | bool comp(pair <string,int> p1, pair <string,int>p2){ |
| 48 | if (p1.second>=p2.second) return true; |