[Offer收割]编程练习赛7 register

Ended

Participants:506

Verdict:Accepted
Score:100 / 100
Submitted:2016-08-28 12:30:16

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>
#include <vector>
#include <cstring>
#include <algorithm>
#include <functional>
using namespace std;
const int N = 26;
struct Node {
    Node() : terminal(false) {
        memset(alpha, NULL, sizeof(alpha));
    }
    bool terminal;
    Node* alpha[N];
};
void insert(Node* root, string& word) {
    Node* p = root;
    for (char c : word) {
        int id = c - 'a';
        if (p->alpha[id] == NULL) {
            p->alpha[id] = new Node;
        }
        p = p->alpha[id];
    }
    p->terminal = true;
}
bool search(Node* root, string& word) {
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX