trie前缀树+字典树

trie前缀树+字典树
题目:POJ2001
题意:找出能唯一标示一个字符串的最短前缀,如果找不出,就输出该字符串

#include 
using namespace std;
struct node{
    int cnt;
    struct node *next[26];
    node(){
        cnt =0;
        memset(next,0,sizeof(next));
    }
};node *root = NULL;
char str[1003][30];
void maketrie(char *s){
    node*p = root;node*temp = NULL;
        for(int i=0;inext[s[i]-'a']==NULL){
            temp = new node;
            p->next[s[i]-'a']=temp;
        }
        p = p->next[s[i]-'a'];
        p->cnt++;
    }
}
void search(char *s){
    node *p =root;
    for(int i=0;inext[s[i]-'a'];
        cout<cnt==1)break;
    }
}
int main(){
    int num;cin>>num;
    root = new node;
    for(int i=0;i>str[i];
        maketrie(str[i]);
    }
    for(int i=0;i

 

你可能感兴趣的:(ACM笔记-2串树)