字典树裸题

 #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 单词数 字典树的更多相关文章

  1. HihoCoder1366 逆序单词(字典树)

    逆序单词 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 在英文中有很多逆序的单词,比如dog和god,evil和live等等. 现在给出一份包含N个单词的单词表,其中每 ...

  2. Java实现 LeetCode 720 词典中最长的单词(字典树)

    720. 词典中最长的单词 给出一个字符串数组words组成的一本英语词典.从中找出最长的一个单词,该单词是由words词典中其他单词逐步添加一个字母组成.若其中有多个可行的答案,则返回答案中字典序最 ...

  3. [HDU2072]单词数<字符串>

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=2072 Problem Description lily的好朋友xiaoou333最近很空,他想了一件没有什 ...

  4. 字典树Trie的使用

    1. Trie树介绍 Trie,又称单词查找树.前缀树,是一种多叉树结构.如下图所示: 上图是一棵Trie树,表示了关键字集合{“a”, “to”, “tea”, “ted”, “ten”, “i”, ...

  5. hdu 1247:Hat’s Words(字典树,经典题)

    Hat’s Words Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  6. hdu1247(字典树+枚举)

    Hat's Words(hdu1247) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...

  7. hdu 1247 (字典树入门)

    Hat’s Words Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  8. HDU1247(经典字典树)

    Hat’s Words Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  9. ZOJ 3674 Search in the Wiki(字典树 + map + vector)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4917 题意:每一个单词都一些tips单词. 先输入n个单词和他们的t ...

随机推荐

  1. Shiny+SQLite打造轻量级网页应用

    参考: R语言核心技能:交互式展示Shiny  中文 R语言用Shiny包快速搭建交互网页应用  R七种武器之交互化展示包shiny 用R的shiny包写一个基因的ID转换小程序 https://gi ...

  2. G1收集器

    转载:https://blog.csdn.net/zhou2s_101216/article/details/79202893 http://blog.jobbole.com/109170/ http ...

  3. EchoService

    dubbo为consumer端的代理对象实现了EchoService接口. 使用示例: <dubbo:reference id="hello" interface=" ...

  4. dup的使用(二)

    转自:http://blog.csdn.net/yeyuangen/article/details/6852682 一个进程在此存在期间,会有一些文件被打开,从而会返回一些文件描述符,从shell中运 ...

  5. JavaScript学习总结(三)——逻辑And运算符详解

    在JavaScript中,逻辑 AND 运算符用双和号(&&)表示 1 var bTrue = true; 2 var bFalse = false; 3 var bResult = ...

  6. learning scala read from console

    控制台输入语句: readInt, readDouble, readByte, readShort, readLong, readChar, readBoolean, readLine example ...

  7. bzoj1600

    题解: 简单dp 显然不能超过一半 代码: #include<bits/stdc++.h> using namespace std; ][]; int main() { f[][]=; s ...

  8. Python 数据类型--字典类型

    字典 dict 字典是Python的另一种有序的可变数据结构,且可存储任意类型对象. 字典是一种键值对的数据容器,每个键值(key:value)对用冒号(:)分割,每个对之间用逗号(,)分割,整个字典 ...

  9. 重置delphi Printer对象

    http://www.efg2.com/Lab/Library/UseNet/1999/0714b.txt From: "Nick Ryan" <nick@avatardes ...

  10. C++基础:什么是命名空间

    命名空间是类的逻辑分组,它组织成一个层次结构——逻辑树.这个树的根是System.名字空间是为了防止名字污染在标准C++中引入的.它可以将其中定义的名字隐藏起来,不同的名字空间中可以有相同的名字而互不 ...