他妹的。敲完了。电脑死机了,所有消失了,又从新打了一遍,。。。

这是什么节奏

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define ZERO 0
#define ALPH_LEN 26 /* 26个字母 */
const char FIRST_CHAR = 'a'; typedef struct node
{
struct node *child[ALPH_LEN]; /* 存储下一个字符 */
int n; /* 记录当前单词出现的次数 */
}node, *Node; Node root; /* 字典树的根结点(不存储不论什么字符) */
/* 插入单词 */
void insert(char *str)
{
int i, index, len;
Node current = NULL, newnode = NULL; len = strlen(str); current = root; /* 開始时当前的结点为根结点 */
for (i = 0; i < len; i++) /* 逐个字符插入 */
{
index = str[i] - FIRST_CHAR; /* 获取此字符的下标 */
if (current->child[index] != NULL) /* 字符已在字典树中 */
{
current = current->child[index]; /* 改动当前的结点位置 */
(current->n)++; /* 当前单词又出现一次, 累加 */
}
else /* 此字符还没出现过, 则新增结点 */
{
newnode = (Node)calloc(1, sizeof(node)); /* 新增一结点, 并初始化 */
current->child[index] = newnode;
current = newnode; /* 改动当前的结点的位置 */
current->n = 1; /* 此新单词出现一次 */
}
}
}
/* 在字典树中查找单词 */
int find_word(char *str)
{
int i, index, len;
Node current = NULL; len = strlen(str); current = root; /* 查找从根结点開始 */
for (i = 0; i < len; i++)
{
index = str[i] - FIRST_CHAR; /* 获取此字符的下标 */
if (current->child[index] != NULL) /* 当前字符存在字典树中 */
{
current = current->child[index]; /* 改动当前结点的位置 */
}
else
{
return ZERO; /*还没比較完就出现不匹配, 字典树中没有此单词*/
}
} return current->n; /* 此单词出现的次数 */
} int main()
{
char tmp[11];
int i; root = (Node)calloc(1, sizeof(node)); while (gets(tmp), strcmp(tmp, "") != ZERO)
{
insert( tmp );
} while (scanf("%s", tmp) != EOF)
{
i = find_word( tmp );
printf("%d\n", i);
} return 0;
}

hdu 1251 统计的更多相关文章

  1. hdu 1251 统计难题 (字典树入门题)

    /******************************************************* 题目: 统计难题 (hdu 1251) 链接: http://acm.hdu.edu. ...

  2. HDU 1251 统计难题(Trie模版题)

    统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others) Total Subm ...

  3. hdu 1251 统计难题(字典树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1251 统计难题 Time Limit: 4000/2000 MS (Java/Others)    M ...

  4. HDU 1251 统计难题 (Trie)

    pid=1251">统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/ ...

  5. hdu 1251 统计难题(trie 树的简单应用)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意:给你多个字符串,求以某个字符串为前缀的字符串数量. 思路:简单的trie数应用,在trie ...

  6. HDU 1251 统计难题(字典树模板题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意:给出一些单词,然后有多次询问,每次输出以该单词为前缀的单词的数量. 思路: 字典树入门题. #inc ...

  7. HDU 1251 统计难题(字典树 裸题 链表做法)

    Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己 ...

  8. 字典树 HDU 1251 统计难题

    ;} 之前写的#include<iostream> #include<algorithm> #include<stdio.h> using namespace st ...

  9. hdu -1251 统计难题(字典树水题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1251 建树之后 查询即可. G++提交 ME不知道为什么,c++就对了. #include <iostre ...

  10. HDU 1251统计难题

    统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others)Total Submi ...

随机推荐

  1. 4. COLLATION_CHARACTER_SET_APPLICABILITY

    4. COLLATION_CHARACTER_SET_APPLICABILITY 表COLLATION_CHARACTER_SET_APPLICABILITY表示哪种字符集适用于哪种排序规则. INF ...

  2. qemu-img命令

    qemu-img是QEMU的磁盘管理工具,在qemu-kvm源码编译后就会默认编译好qemu-img这个二进制文件.qemu-img也是QEMU/KVM使用过程中一个比较重要的工具,本节对其用法和实践 ...

  3. (二十)python 3 匿名函数

    匿名函数lambda Python使用lambda关键字创造匿名函数.所谓匿名,意即不再使用def语句这样标准的形式定义一个函数.这种语句的目的是由于性能的原因,在调用时绕过函数的栈分配.其语法是: ...

  4. 第九节:pandas打印设置

    get_option() :获取系统默认设置选项: set_option() :设置系统设置选项.

  5. STM32--TIM定时器时钟分割(疑难)

    不太明白 (1)        TIM_Perscaler来设置预分频系数: (2)        TIM_ClockDivision来设置时钟分割(时钟分频因子): (3)        TIM_C ...

  6. 如何使用werkzeug创建WSGI APP

    注意 : 1.定义__call__的意义 class App(): def __init__(self): pass def method(self): pass app=App() app() #错 ...

  7. oracle 恢复中的switch datafile all是什么意思

    使用rman进行恢复时,如果使用了set name修改文件路径,那么恢复后,控制文件里面的信息是没有修改该的,如果要同步控制文件的信息那么就需要使用 switch datafile allall这个可 ...

  8. 怎样检查Android网络连接状态

    在发送任何HTTP请求前最好检查下网络连接状态,这样可以避免异常.这个教程将会介绍怎样在你的应用中检测网络连接状态. 创建新的项目 1.在Eclipse IDE中创建一个新的项目并把填入必须的信息.  ...

  9. 【HDOJ6308】Time Zone(模拟)

    题意: 以"UTC+X'', "UTC-X'', "UTC+X.Y'', or "UTC-X.Y'' 四种格式给定当地时间,要求转换为北京时间 思路:Gold_ ...

  10. BZOJ2059: [Usaco2010 Nov]Buying Feed 购买饲料

    数轴上n<=500个站可以买东西,每个站位置Xi,库存Fi,价格Ci,运东西价格是当前运载重量的平方乘距离,求买K<=10000个东西到达点E的最小代价. f[i,j]--到第i站不买第i ...