题目链接:http://poj.org/problem?id=1056
思路:
字典树的简单应用,就是判断当前所有的单词中有木有一个是另一个的前缀,直接套用模板再在Tire定义中加一个bool类型的变量用来判断当前到达的位置是否构成另一个单词的编码
代码:
1 #include<cstdio> 2 #include<cstdlib> 3 #include<iostream> 4 #include<algorithm> 5 #include<cstring> 6 using namespace std; 7 const int MAX=2; 8 class Trie 9 { 10 public: 11 bool isCode; 12 Trie *next[MAX]; 13 }; 14 bool flag; 15 16 void Build_Tree(Trie *root,char *str) 17 { 18 Trie *p=root; 19 int i=0; 20 while(str[i]!='