hiho Week 2 register

Ended

Participants:1624

Verdict:Accepted
Score:100 / 100
Submitted:2014-07-14 20:42:41

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<iostream>
#include<string>
using namespace std;
#define MAX 26
struct trie_node//node
{
 int count;
 trie_node *next[MAX];
};
void node_insert(trie_node *root,string s)//insert a new string
{
 if(root==NULL||s.size()==0)
  return;
 int i=0;
 trie_node *p=root;
    while(s[i]!='\0')
 {
  if(s[i]>='a'&&s[i]<='z')
  {
           if(p->next[s[i]-'a']==NULL)//if do not exit,build a new node;
           {
      /* build a new node */
      trie_node *temp=new trie_node;
      temp->count=0;
      for(int j=0;j<MAX;j++)
       temp->next[j]=NULL;
      p->next[s[i]-'a']=temp;//change p
     }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX