二次联通门 : codevs 1729 单词查找树

/*
codevs 1729 单词查找树 Trie树 统计节点个数
建一棵Trie树
插入单词时每新开一个节点就计数器加1 */
#include <cstdio>
#include <cstring>
#include <cstdlib> void read (int &now)
{
now = ;
register char word = getchar ();
while (word < '' || word > '')
word = getchar ();
while (word >= '' && word <= '')
{
now = now * + word - '';
word = getchar ();
}
} struct Trie_Type
{ struct Trie
{
Trie *next[];
bool Add_flag;
bool flag;
}; Trie Root; int Count; void Insert (char *line)
{
int Length = strlen (line);
Trie *now = &Root;
Trie *res;
for (int i = ; i < Length; i++)
{
int name = line[i] - 'A';
if (now->next[name] == NULL)
{
res = (Trie *) malloc (sizeof Root);
res->flag = true;
for (int j = ; j < ; j++)
res->next[j] = NULL;
now->next[name] = res;
Count++;
now = now->next[name];
}
else
{
now->next[name]->flag = true;
now = now->next[name];
}
}
} void Clear ()
{
for (int i = ; i < ; i++)
Root.next[i] = NULL;
} }; Trie_Type Make;
int N; int main (int argc, char *argv[])
{
Make.Clear ();
register char word[];
while (scanf ("%s", word) != EOF)
Make.Insert (word);
printf ("%d", Make.Count + );
return ;
}
05-14 13:13