hiho Week 2 register

Ended

Participants:1624

Verdict:Accepted
Score:100 / 100
Submitted:2014-07-14 00:10:32

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>
using namespace std;
#define MAX 26
typedef struct TrieTree {
    int count;
    struct TrieTree *next[MAX];
}TrieTree;
TrieTree *insert(TrieTree **root, const char *s)
{
    if (*root == NULL && s == NULL)
        return NULL;
    TrieTree *index = *root;
    while (*s != '\0')
    {
        int tmp = (*s) - 'a';
        if (index->next[tmp] != NULL)
        {
            index = index->next[tmp];
            index->count++;
        }
        else
        {
            TrieTree *newnode = new TrieTree;
            for (int i = 0; i < MAX; i++)
                newnode->next[i] = NULL;
            newnode->count = 1;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX