Bootstrap

字典树模板(完整版)

#include "bits/stdc++.h"
using namespace std;
const int maxn = 1000005;
int trie[maxn][26];
int num[maxn];
int cnt;
void init(){ //初始化
    for(int i=0;i<=cnt;i++){
        num[i]=0;
        for(int j=0;j<=26;j++){
            trie[i][j]=0;
        }
    }
    cnt=0;
}
void insert_s(char *s) { //插入
    int n = strlen(s);
    int root = 0;
    for (int i = 0; i < n; i++) {
        int k = s[i] - 'a';
        if (!trie[root][k]) {
            trie[root][k] = ++cnt;
        }
        root = trie[root][k];
        num[root]++;
    }
}
int find_s(char *s) { //查找
    int n = strlen(s);
    int root = 0;
    for (int i = 0; i < n; i++) {
        int k = s[i] - 'a';
        if (!trie[root][k]) {
            return 0;
        }
        root = trie[root][k];
    }
    return num[root];
}
void delete_
;