字典树裸题

 #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+Mybatis-Generator自动生成

    原文链接 1.版本 Spring Boot 1.5.10 mybatis-generator-core 1.3.5 mybatis-generator-maven-plugin 1.3.5 2.项目目 ...

  2. 笔试题-sql语句

    今天遇到了不熟练(不会)的查询题目 回来自己又做了一下,如下 建表语句 -- Table structure for score -- ---------------------------- DRO ...

  3. 高精度乘法,string中的坑

    #include "bits/stdc++.h" using namespace std; ]; ]; int main() { while(cin >> a > ...

  4. 第5章——使用 Razor(MVC框架视图引擎)

    Razor 是MVC框架视图引擎的名称. 本章提供 Razor 语法的快速教程,以使你能够识别 Razor 表达式. 本章不打算提供 Razor 的完整参考,而将其视为一个语法速成教程.在本书的后续内 ...

  5. xmind visio mindmanager edraw比较

    xmind visio mindmanager edraw比较   xmind visio mindmanager Edraw 中心主题 有 无 有   泳道图 无 有 有   结构上讲 [思维导图] ...

  6. PHP:第一章——PHP中逻辑运算符的使用方法

    //逻辑运算符 $a=;$b=;$c=;$d=; //逻辑与(and 和 &&)他们两个的逻辑是一样的,如果两个值都为true,结果才为true,否则是false. //var_dum ...

  7. httpclient http状态管理

    HTTP状态管理 最初,Htt被设计成一个无状态的面向请求响应的协议,所以它不能再逻辑相关的http请求/响应中保持状态会话. 由于越来越多的系统使用http协议,其中包括http从来没有想支持的系统 ...

  8. mysql监控利器mysqlmtop部署安装

    MySQLMTOP是一个由Python+PHP开发的MySQL企业级监控系统.系统由Python实现多进程数据采集和告警,PHP实现WEB展示和管理.最重要是MySQL服务器无需安装任何Agent,只 ...

  9. 跟我一起学习ASP.NET 4.5 MVC4.0(六)

    这一系列文章跨度有点大,由于最近忙于其他事情,没有更新,今天重新安装了下Win8系统,VS2012和SQLServer 2012,顺便抽空继续一篇.随着VS2012 RC版本的放出,ASP.NET M ...

  10. tcp/ip协议之小解释

    [转载] http://www.ruanyifeng.com/blog/2009/03/tcp-ip_model.html