hdu5687

 #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+, n = ;
struct node {
int next[];
int cnt;
void init() {
cnt = ;
memset(next,-,sizeof(next));
}
};
node trie[maxn*n];
int tot = ;
void insert(char *s) {
int cur = , len = strlen(s);
for (int i = ; i < len; i++) {
int temp = s[i]-'a';
int next = trie[cur].next[temp];
if (next == -) {
next = ++tot;
trie[next].init();
trie[cur].next[temp] = next;
}
cur = next;
trie[cur].cnt++;
}
}
bool find(char *s) {
int cur = , len = strlen(s);
for (int i = ; i < len; i++) {
int temp = s[i]-'a';
int next = trie[cur].next[temp];
if (next == -) return false;
cur = next;
}
return trie[cur].cnt > ;
}
void del(char * s) {
int cur = , late, len = strlen(s);
for (int i = ; i < len; i++) {
int temp = s[i]-'a';
int next = trie[cur].next[temp];
if (next == -) return;
late = cur;
cur = next;
}
cur = ;
for (int i = ; i < len; i++) {
int temp = s[i]-'a';
int next = trie[cur].next[temp];
late = cur;
cur = next;
trie[cur].cnt--;
}
trie[cur].init();
int temp = s[len-]-'a';
trie[late].next[temp] = -;
}
int main() {
int n; scanf("%d",&n);
char cmd[], word[];
for (int i = ; i <= n; i++) {
scanf("%s%s",cmd,word);
if (cmd[] == 'i') insert(word);
else if (cmd[] == 's') {
if (find(word)) puts("Yes");
else puts("No");
}
else del(word);
}
return ;
}

hdu5687 字典树的更多相关文章

  1. 萌新笔记——用KMP算法与Trie字典树实现屏蔽敏感词(UTF-8编码)

    前几天写好了字典,又刚好重温了KMP算法,恰逢遇到朋友吐槽最近被和谐的词越来越多了,于是突发奇想,想要自己实现一下敏感词屏蔽. 基本敏感词的屏蔽说起来很简单,只要把字符串中的敏感词替换成"* ...

  2. [LeetCode] Implement Trie (Prefix Tree) 实现字典树(前缀树)

    Implement a trie with insert, search, and startsWith methods. Note:You may assume that all inputs ar ...

  3. 字典树+博弈 CF 455B A Lot of Games(接龙游戏)

    题目链接 题意: A和B轮流在建造一个字,每次添加一个字符,要求是给定的n个串的某一个的前缀,不能添加字符的人输掉游戏,输掉的人先手下一轮的游戏.问A先手,经过k轮游戏,最后胜利的人是谁. 思路: 很 ...

  4. 萌新笔记——C++里创建 Trie字典树(中文词典)(一)(插入、遍历)

    萌新做词典第一篇,做得不好,还请指正,谢谢大佬! 写了一个词典,用到了Trie字典树. 写这个词典的目的,一个是为了压缩一些数据,另一个是为了尝试搜索提示,就像在谷歌搜索的时候,打出某个关键字,会提示 ...

  5. 山东第一届省赛1001 Phone Number(字典树)

    Phone Number Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 We know that if a phone numb ...

  6. 字典树 - A Poet Computer

    The ACM team is working on an AI project called (Eih Eye Three) that allows computers to write poems ...

  7. trie字典树详解及应用

    原文链接    http://www.cnblogs.com/freewater/archive/2012/09/11/2680480.html Trie树详解及其应用   一.知识简介        ...

  8. HDU1671 字典树

    Phone List Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  9. *HDU1251 字典树

    统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others)Total Submi ...

随机推荐

  1. thinkphp5--model数据操作的坑

    最近用thinkphp5开发,经常用到model了来操作数据,但是操作多了,就发现他的坑了. 就好像如果你只是初始化一个model对象,但是你却用这个对象进行多次的数据操作,这时候他的数据就会发生混乱 ...

  2. Windows挂载Gluster复制卷

    本地挂载测试 mount -t glusterfs 127.0.0.1:/gv1 /mnt [root@gluster1 mnt]# df -h Filesystem Size Used Avail ...

  3. Codeforces Round #635 (Div. 2) 题解

    渭城朝雨浥轻尘,客舍青青柳色新. 劝君更尽一杯酒,西出阳关无故人.--王维 A. Ichihime and Triangle 网址:https://codeforces.com/contest/133 ...

  4. Libra教程之:Libra protocol的逻辑数据模型

    文章目录 Libra protocol简介 逻辑数据模型 账本状态 交易 账本历史 Libra protocol简介 Libra区块链本质上是一个加密数据库,这个数据库是通过Libra protoco ...

  5. mysql备份及恢复

    第四章:MySQL数据库的备份与恢复                            2016-09-30 00:58:05 标签:数据库备份 工作原理 数据库表 mysql source 原创 ...

  6. MySQL用另一张表的字段值Update本表

    SQL示例: UPDATE TABLE1 a, TABLE2 b SET a.field1 = b. field1 [, a.field2 = b.field2, ...] WHERE a.connn ...

  7. nat和静态映射

    拓扑图: 实验要求: 1.R2.R3能访问外网的4.4.4.4(4.4.4.4为R4上的环回接口,用来模拟inter网). 2.R4访问222.222.222.100其实访问到的是内网的192.168 ...

  8. 动态规划经典算法--最长公共子序列 LCS

    转移方程 代码: //法一: #include <bits/stdc++.h> using namespace std; //---------------https://lunatic. ...

  9. 更安全的rm命令,保护重要数据

    更安全的rm命令,保护重要数据 网上流传的安全的rm,几乎都是提供一个rm的"垃圾"回收站,在服务器环境上来说,这实非良方. 我想,提供一个安全的rm去保护一些重要的文件或目录不被 ...

  10. jQuery中bind()与on()绑定事件的区别

    .on()方法比.bind()方法多一个参数selector .on()的selector参数是筛选出调用.on()方法的dom元素的指定子元素,如: $("ul").on('cl ...