字典树裸题

 #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. webpack和tree shaking和rollup

    http://blog.csdn.net/haodawang/article/details/77199980 tree shaking只对es模块生效,在打包tyscript模块是要使用tsc编译器 ...

  2. Lua---执行

    1.交互式: 2.脚本式(在命令行不要启动lua解释器,直接输): Testlua.lua 的内容: print("Hello World!")

  3. delphi文件名获取方法

    取文件名 ExtractFileName(FileName); 取文件扩展名: ExtractFileExt(filename); 取文件名,不带扩展名: 方法一:   Function Extrac ...

  4. (Gorails)vuejs系列视频: Webpacker/vue-resource(不再为官方推荐)。

    频:https://gorails.com/episodes/using-vuejs-for-nested-forms-part-1?autoplay=1 在嵌套表格上使用vue.js. 在appli ...

  5. 1月11日Atom 插件安装。

    查看已安装的Atom插件(前提:已经安装Atom) 打开终端 输入apm ls命令,回车. 未安装任何插件时,显示如下 Built-in Atom packages (89) ...此处省略... / ...

  6. python-day14--带参数的装饰器+多个装饰器装饰同一个函数

    1.# 带参数的装饰器def f1(flag): def f2(func): def inner(*args,**kwargs): if flag: '''执行函数之前要做的''' r=func(*a ...

  7. zzuli1731 矩阵(容斥)

    1731: 矩阵 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 600  Solved: 106 SubmitStatusWeb Board Descr ...

  8. MySQL 事件跟踪器

    /*第一步 创建以下两个 日志表 */ CREATE TABLE `slow_log` ( `start_time` timestamp NOT NULL DEFAULT CURRENT_TIMEST ...

  9. [LeetCode] 41. First Missing Positive ☆☆☆☆☆(第一个丢失的正数)

    Given an unsorted integer array, find the smallest missing positive integer. Example 1: Input: [1,2, ...

  10. Sql Server中集合的操作(并集、差集、交集)学习

    首先我们做一下测试数据 1.创建测试数据 --创建人员表1-- create table Person1 ( Uid ,) primary key, Name ) not null ) --创建人员表 ...