#include<stdio.h>

#include<iostream>

#include<string.h>

using namespace std;

struct node {

int num,i;

node *a[27];

node (){

num=0;

for(i=0;i<27;i++)

a[i]=NULL;

}

}*root;

char str[20];

void insert(int len,node *root) {

int i;

node *q;

for(i=0;i<len;i++) {

if(root->a[str[i]-'a']==NULL) {

q=new node();

q->num++;

root->a[str[i]-'a']=q;

root=q;

}

else  {

root=root->a[str[i]-'a'];

root->num++;

}

}

return ;

}

int find(int len,node *root) {

int i;

for(i=0;i<len;i++) {

root=root->a[str[i]-'a'];

if(root==NULL)

return 0;

}

return root->num;

}

int main() {

int k;

root=new node();

while(gets(str)&&str[0]!='\0') //输入条件太恶心了

insert(strlen(str),root);

while(scanf("%s",str)!=EOF) {

k=find(strlen(str),root);

printf("%d\n",k);

}

return 0;

}

hdu 1251简单字典树的更多相关文章

  1. hdu 1979 DFS + 字典树剪枝

    http://acm.hdu.edu.cn/showproblem.php?pid=1979 Fill the blanks Time Limit: 3000/1000 MS (Java/Others ...

  2. hdu 2846(字典树)

    Repository Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  3. HDU 2846 Repository (字典树 后缀建树)

    Repository Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total ...

  4. HDU 1671 (字典树统计是否有前缀)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1671 Problem Description Given a list of phone number ...

  5. HDU 1298 T9 ( 字典树 )

    题意 : 给你 w 个单词以及他们的频率,现在给出模拟 9 键打字的一串数字,要你在其模拟打字的过程中给出不同长度的提示词,出现的提示词应当是之前频率最高的,当然提示词不需要完整的,也可以是 w 个单 ...

  6. HDU 2846 Repository(字典树,标记)

    题目 字典树,注意初始化的位置~!!位置放错,永远也到不了终点了org.... 我是用数组模拟的字典树,这就要注意内存开多少了,,要开的不大不小刚刚好真的不容易啊.... 我用了val来标记是否是同一 ...

  7. *hdu 5536(字典树的运用)

    Input The first line of input contains an integer T indicating the total number of test cases. The f ...

  8. three arrays HDU - 6625 (字典树)

    three arrays \[ Time Limit: 2500 ms \quad Memory Limit: 262144 kB \] 题意 给出 \(a\),\(b\) 数组,定义数组 \(c[i ...

  9. POJ2503(Babelfish)--简单字典树

    思路:就是用一个字典树翻译单词的问题,我们用题目中给出的看不懂的那些单词建树,这样到每个单词的叶子结点中存放原来对应的单词就好. 这样查询到某个单词时输出叶子结点存的就行,查不到就"en&q ...

随机推荐

  1. SpringBoot 2.x (4):配置文件与单元测试

    SpringBoot的配置文件有默认的application.properties 还可以使用YAML 区别: application.properties示例: server.port=8090 s ...

  2. [POJ1509]Glass Beads 后缀自动机 最小循环串

    题目链接:http://poj.org/problem?id=1509 题目意思就是求循环字符串的最小表示. 我们用字符串S+S建立SAM,然后从root开始走n步,每次尽量选最小的. 由于 SAM ...

  3. WPF 实时绘图的逻辑

    实时绘图实际上是两个线程.外部线程直接用thread,只有到绘图那个逻辑才用绘图控件的mycanvas2.Dispatcher.Invoke. 或者说,INVOKE并不是开线程,只是一个绘图的委托而已 ...

  4. 微信小程序组件解读和分析:十四、slider滑动选择器

    slider滑动选择器组件说明: 滑动选择器. slider滑动选择器示例代码运行效果如下: 下面是WXML代码: [XML] 纯文本查看 复制代码 ? 01 02 03 04 05 06 07 08 ...

  5. git ---匿名分支和checkout命令

    git checkout -b   //创建一个匿名分支

  6. C语言基础-循环结构

    循环结构while while循环-图例 while循环-格式 while ( 条件 ) { 语句1; 语句2; .... } 如果条件成立,就会执行循环体中的语句(“循环体”就是while后面大括号 ...

  7. MYSQL 查询方法 统计查询 链接查询 子查询

    mysql表格查询方法: 查询: 1.简单查询 select * from Info --查所有数据select Code,Name from Info --查指定列的数据select Code as ...

  8. (二)Redis for 阿里云公网连接

    目录 (一)Redis for Windows正确打开方式 (二)Redis for 阿里云公网连接 (三)Redis for StackExchange.Redis 阿里云目前仅支持内网连接Redi ...

  9. discuz 插件核心函数hookscript分析.

    function hookscript($script, $hscript, $type = 'funcs', $param = array(), $func = '', $scriptextra = ...

  10. CAD参数绘制半径标注(com接口)

    主要用到函数说明: _DMxDrawX::DrawDimRadial 绘制一个半径标注.详细说明如下: 参数 说明 DOUBLE dCenterX 被标注的曲线的中点X值 DOUBLE dCenter ...