hdu 1251 统计
他妹的。敲完了。电脑死机了,所有消失了,又从新打了一遍,。。。
这是什么节奏
#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 统计的更多相关文章
- hdu 1251 统计难题 (字典树入门题)
/******************************************************* 题目: 统计难题 (hdu 1251) 链接: http://acm.hdu.edu. ...
- HDU 1251 统计难题(Trie模版题)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others) Total Subm ...
- hdu 1251 统计难题(字典树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1251 统计难题 Time Limit: 4000/2000 MS (Java/Others) M ...
- HDU 1251 统计难题 (Trie)
pid=1251">统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/ ...
- hdu 1251 统计难题(trie 树的简单应用)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意:给你多个字符串,求以某个字符串为前缀的字符串数量. 思路:简单的trie数应用,在trie ...
- HDU 1251 统计难题(字典树模板题)
http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意:给出一些单词,然后有多次询问,每次输出以该单词为前缀的单词的数量. 思路: 字典树入门题. #inc ...
- HDU 1251 统计难题(字典树 裸题 链表做法)
Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己 ...
- 字典树 HDU 1251 统计难题
;} 之前写的#include<iostream> #include<algorithm> #include<stdio.h> using namespace st ...
- hdu -1251 统计难题(字典树水题)
http://acm.hdu.edu.cn/showproblem.php?pid=1251 建树之后 查询即可. G++提交 ME不知道为什么,c++就对了. #include <iostre ...
- HDU 1251统计难题
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
随机推荐
- 1.INFORMATION_SCHEMA简介
1. INFORMATION_SCHEMA简介 INFORMATION_SCHEMA提供对数据库元数据的访问,有关MySQL服务器信息,例如数据库或表的名称,列的数据类型或访问权限. INFORMAT ...
- ubuntu修改网卡名称ensX为eth0
1.sudo nano /etc/default/grub 找到GRUB_CMDLINE_LINUX="" 改为GRUB_CMDLINE_LINUX="net.ifnam ...
- C++:别名 / 引用 的简单实用
文章来源:http://www.cnblogs.com/hello-tl/p/7910048.html /* C++别名操作 在更改别名的时候同时变量也会跟着改变 */ #include " ...
- python-爬虫学习(文字、图片、视频)
爬虫-文字爬取 import re import requests respone = requests.get('https://ishuo.cn/') ##获取网站url data = respo ...
- Linux项目发布流程
Linux项目发布流程(一) 1.安装pyhton3.7 的依赖包 yum -y groupinstall "Development tools" yum -y install z ...
- 给Django中的url起名字
url反转 =>reverse 1.from django.shortcuts import reverse 2. 利用reverse函数对URL名称进行反转 reverse(url名称 ...
- Huffman codes
05-树9 Huffman Codes(30 分) In 1953, David A. Huffman published his paper "A Method for the Const ...
- Java学习之跳转语句
Java语言中提供3中跳转语句,分别是break语句.continue语句和return语句. break语句 可以用在switch语句中.在switch语句中,break语句用于中止下面的case语 ...
- C#窗体学生成绩管理系统
c#学生成绩管理系统 实现用户登录.注册 所有成绩查询.个人成绩查询 管理员审核.添加.删除用户 项目源码GIT:https://github.com/soulsjie/StuScoreMa.git
- hdu 2579
#include<stdio.h> #include<queue> #include<iostream> #include<string.h> #inc ...