hdu2072 单词数 字典树
字典树裸题
#include<stdio.h>
#include<string.h>
int next[][];
bool is_e[];
int cnt;
int ans; void Insert(char *word,int s1){
int root=;
for(int i=;i<s1;i++){
if(next[root][word[i]-'a']<){
next[root][word[i]-'a']=++cnt;
memset(next[cnt],-,sizeof(next[cnt]));
}
root=next[root][word[i]-'a'];
}
if(is_e[root]!=true&&root!=){
ans++;
is_e[root]=true;
}
} int main(){
char word[];
while(){ int s1=;
ans=;
cnt=;
memset(is_e,false,sizeof(is_e));
memset(next[],-,sizeof(next[]));
gets(word);
if(word[]=='#')return ;
int l=strlen(word);
char *p=word;
for(int i=;i<l;i++){
if(word[i]!=' '){
s1++;
}
else{
Insert(p,s1);
s1=;
p=(word+i+);
}
}
Insert(p,s1);
printf("%d\n",ans);
}
}
hdu2072 单词数 字典树的更多相关文章
- HihoCoder1366 逆序单词(字典树)
逆序单词 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 在英文中有很多逆序的单词,比如dog和god,evil和live等等. 现在给出一份包含N个单词的单词表,其中每 ...
- Java实现 LeetCode 720 词典中最长的单词(字典树)
720. 词典中最长的单词 给出一个字符串数组words组成的一本英语词典.从中找出最长的一个单词,该单词是由words词典中其他单词逐步添加一个字母组成.若其中有多个可行的答案,则返回答案中字典序最 ...
- [HDU2072]单词数<字符串>
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2072 Problem Description lily的好朋友xiaoou333最近很空,他想了一件没有什 ...
- 字典树Trie的使用
1. Trie树介绍 Trie,又称单词查找树.前缀树,是一种多叉树结构.如下图所示: 上图是一棵Trie树,表示了关键字集合{“a”, “to”, “tea”, “ted”, “ten”, “i”, ...
- hdu 1247:Hat’s Words(字典树,经典题)
Hat’s Words Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- hdu1247(字典树+枚举)
Hat's Words(hdu1247) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- hdu 1247 (字典树入门)
Hat’s Words Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- HDU1247(经典字典树)
Hat’s Words Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- ZOJ 3674 Search in the Wiki(字典树 + map + vector)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4917 题意:每一个单词都一些tips单词. 先输入n个单词和他们的t ...
随机推荐
- Java中classpath配置
Java中classpath配置 一.DOS常用命令 二.DOS常用命令实例 2.1 转换目录 cd 1.6* 2.2 删除文件 del 删除文件(windows删除从里往外删) del *.txt ...
- freemarker中对null值问题的处理
1. freemarker不支持null. 如果值为null会报错. 2.当值为null的处理 1)过滤不显示 Hello ${name!} 在属性后面加感叹号即可过滤null和空字符串 if和”?? ...
- [Java学习] Java super关键字
super 关键字与 this 类似,this 用来表示当前类的实例,super 用来表示父类. super 可以用在子类中,通过点号(.)来获取父类的成员变量和方法.super 也可以用在子类的子类 ...
- Loading Xps from MemoryStream
A common way of loading XpsDocument is to load it from file: XpsDocument document = new XpsDocument( ...
- php--------文件夹文件拷贝和复制
php开发中常常对文件进行操作,文件夹和文件的拷贝,复制等. /** * 文件夹文件拷贝 * * @param string $src 来源文件夹 * @param string $dst 目的地文件 ...
- 『Python』pycharm常用设置
学习一下pycharm的快捷操作,提升速度,也提升舒适度,笑. 常用快捷键 ctrl + d :复制粘贴本行到下一行 ctrl + y :删除本行 ctrl + 鼠标点击 :跳转 ctrl + / : ...
- LeetCode 318. Maximum Product of Word Lengths (状态压缩)
题目大意:给出一些字符串,找出两个不同的字符串之间长度之积的最大值,但要求这两个字符串之间不能拥有相同的字符.(字符只考虑小写字母). 题目分析:字符最多只有26个,因此每个字符串可以用一个二进制数来 ...
- UVA-10710 Skyscraper Floors (找规律+幂取模)
题目大意:题目中给了一种数的定义,根据定义,让判断一个给定的数是不是这种数.题中叫这种数为吉米数,定义如下:对序列1,2,3,,,,n,做n-1次SF变换(对该变换的解释在下文),如果能得到原序列,则 ...
- Leetcode 94
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode ...
- POJ 2352 treap
当年经常遇到这种题,愣是没做出来,好像那时不会线段树,也不会平衡树. 凭借一身蛮力来搞,倒是和那群朋友搞得开开心心. 题意: y从小到大,若y相同,x从小到大,这样给出一些坐标,求每个点覆盖的点个数. ...