字典树裸题

 #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. SpringBoot 中常用注解@Controller/@RestController/@RequestMapping介绍

    原文 SpringBoot 中常用注解 @Controller/@RestController/@RequestMapping介绍 @Controller 处理http请求 @Controller / ...

  2. English trip V1 - 5.That's Amazing! 棒极了! Teacher:Patrick Key: can or can't

    In this lesson you will learn to describe what people can do. 在本课中,您将学习如何描述人们可以做什么. STARTE drive a c ...

  3. PHP函数总结 (四)

    <?php/** * 引用参数: * 1.PHP默认按值传递参数,父程序(调用函数)与子程序(函数)的数值分别存储与不同的内存区块: * 2.引用传递参数,加符号 & :它是把父程序的数 ...

  4. CF-499div2-E-裴蜀定理

    E. Border time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...

  5. hdu-2509-反nim博弈

    Be the Winner Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  6. UVA-11149 Power of Matrix(矩阵二分幂)

    题目大意:给一个n阶方阵,求A1+A2+A3+......Ak. 题目分析:令F(k)=A1+A2+A3+......Ak.当k为偶数时,F(k)=F(k/2)*(E+Ak/2),k为奇数时,F(k) ...

  7. 批量kill Linux环境下的任务

    批量kill Linux服务器的进程可以通过ps  grep  aws  xargs 进行结合来完成  比如要kill 全部test.sh 的进程 ps -ef |grep "test.sh ...

  8. .net 外部CSS文件不起作用总结

    外部css文件样式全部不起作用 asp.net 页面引用路径的问题 缺少必须属性<link rel="stylesheet" type="text/css" ...

  9. Openwrt WiFi Configure(1)

    1      Scope of Document This document describes how to custom wifi option 2      Requiremen 2.1     ...

  10. sgu114. Telecasting station 难度:1

    114. Telecasting station time limit per test: 0.25 sec. memory limit per test: 4096 KB Every city in ...