统计难题 HDOJ --1251
统计难题
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)
Total Submission(s): 15031 Accepted Submission(s): 6436
注意:本题只有一组测试数据,处理到文件结束.
band
bee
absolute
acm
ba
b
band
abc
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef struct Tree_Node
{
int cnt;
struct Tree_Node *child[];
}Node;
Node *root;
char str[];
void insert()
{
int i;
if(str == NULL)
return ;
char *p = str;
Node *t = root;
while(*p != '\0')
{
if(NULL == t -> child[*p- 'a'])
{
Node *temp = (Node *)malloc(sizeof(Node));
memset(temp, , sizeof(Node));
for(i = ;i < ;i ++)
{
temp -> child[i] = NULL;
temp -> cnt = ;
}
t -> child[*p - 'a'] = temp;
}
t = t -> child[*p - 'a'];
t -> cnt ++;
p ++;
}
}
int search()
{
if(NULL == root)
return ;
char *p = str;
Node *t = root;
while(*p != '\0')
{
if(NULL != t -> child[*p - 'a'])
{
t = t -> child[*p - 'a'];
p ++;
}
else
return ;
}
return t -> cnt;
} int main(int argc, char const *argv[])
{
int i;
char c[] = "abc";
Node TREEROOT;
root = &TREEROOT;
for(i = ;i < ;i ++)
{
root -> child[i] = NULL;
root -> cnt = ;
}
// freopen("in.c","r",stdin);
while(gets(str) && strcmp(str,""))
{
insert();
memset(str, , sizeof(str));
}
memset(str, , sizeof(str));
while(~scanf("%s", str))
{
printf("%d\n", search());
memset(str, , sizeof(str));
}
return ;
}
统计难题 HDOJ --1251的更多相关文章
- AC日记——统计难题 hdu 1251
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- 字典树模板题(统计难题 HDU - 1251)
https://vjudge.net/problem/HDU-1251 标准的字典树模板题: 也注意一下输入方法: #include<iostream> #include<cstdi ...
- hdu 1251 统计难题 (字典树入门题)
/******************************************************* 题目: 统计难题 (hdu 1251) 链接: http://acm.hdu.edu. ...
- hdoj 1251 统计难题 【字典树】
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others) Total Subm ...
- hduoj 1251 统计难题
http://acm.hdu.edu.cn/showproblem.php?pid=1251 统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory ...
- 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统计难题
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
随机推荐
- IOS高级开发 runtime(一)
一. 简介 IOS 开发中灵活使用runtime 会提高我们的程序性能和开发速度.要想使用runtime,首先要引入系统的头文件. <span style="font-size:18p ...
- js 无刷新分页代码
/** * 分页事件处理 */function paging(){ $("#firstPage").click(function(){ //首页 var pageNo = getP ...
- sql server经典sql
1. sql server构造oracle rownum列 select * from ( select row_number() over(order by t.修改时间 desc) rownum, ...
- stringstream vs sprintf, sscanf.
前言 以前一直认为 stringstream 远不如 sprintf. 近日突然萌发了看看 stirngstream 是不是真的如我想的那么烂 对比 // stringstream. stringst ...
- iframe框根据内容自适应高度
1.页面 <iframe name="iframe_userCenter" id="iframe" frameborder=2 width=100% he ...
- windows phone 扫描二维码
在网上找了找扫描二维码的例子,利用ZXing库实现(下载),提供的Silverlight版本的下载,在网上搜了一下已经有wp的dll可用了,不过网上实现的条码扫描的例子还都是用的Silverlight ...
- 常用的工具GCC GDB Make Makefile
系统调用系统调用是操作系统提供给外部应用程序的一组特殊的接口.应用程序通过这组特殊“接口”来获得操作系统内核提供的服务.在 C 语言中,操作系统的系统调用通常通过函数调用的形式完成, 这是因为这些函数 ...
- HTML5 改良的 input 元素的种类
html5中增加改良的input 元素 . 在过去我们制作网页输入框,会用到不少JS验证,如今有了HTML5写这种效果已经没有那么麻烦了,下面我来给大家介绍两种HTML5的input的新增加的类型应用 ...
- php url字符转义操作
遇到一段代码,从数据库里读出来带 \ 字符 需要转义成中文~ 用到url_decode(); //$info 为刚从数据库中读取的二维数组 foreach($info as $key1 => & ...
- maya2105 - windows8 - numpy/scipy
To compile numpy, create a site.cfg file in numpy's source directory with the following or similar c ...