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. 获取 保存 系统信息 [Windows]

    出处:https://www.technig.com/find-windows-10-system-information/ 在“运行”里,运行 msinfo32. System Informatio ...

  2. Net core项目实战篇01---EFCore CodeFirs For Mysql 数据库初始化

    从今天开始我们用Net Core进行项目实战,采用微服务构架,因此你会看到我各模块开始都是用的web api.项目中的代码直接可以复制.费话不多说,现在就来跟我一起开始吧! 1.打开VS2017—&g ...

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

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

  4. JAVA学习之路 (五) 类

    java类的学习 先上一个代码 package bankCard; import java.util.Scanner; // 银行卡类 public class bankCard { // 静态变量 ...

  5. nginx 反向代理转发导致css,js,图片失效

    为什么80%的码农都做不了架构师?>>>   需要添加以下配置 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { proxy_pass htt ...

  6. RHEL6 搭建 keepalived + lvs/DR 集群

    搭建 keepalived + lvs/DR  集群 使用Keepalived为LVS调度器提供高可用功能,防止调度器单点故障,为用户提供Web服务: LVS1调度器真实IP地址为192.168.4. ...

  7. #Week4 Logistic Regression

    一.Classification 主要讨论二元分类. 线性回归处理分类问题显然不靠谱,所以采用逻辑回归. 二.Hypothesis Representation 假设函数变为\(h_\theta(x) ...

  8. document.documentElement.scrollTop指定位置失效解决办法

    近期在vue的H5项目中,做指定位置定位的时候发现使用document.documentElement.scrollTop一直不生效. 解决办法是document.documentElement.sc ...

  9. Codeforces Round #623 (Div. 2, based on VK Cup 2019-2020 - Elimination Round, Engine) C. Restoring

    C. Restoring Permutation time limit per test1 second memory limit per test256 megabytes inputstandar ...

  10. CodeForces - 1058A. In Search of an Easy Problem

    这题,全零是esay有1是hard,真难呀. #include<bits/stdc++.h> using namespace std; int main(){ int n,i,x,flag ...