统计难题 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 ...
随机推荐
- objective-c内存管理中autorelease的作用
//创建自动释放池 @autoreleasepool { //autorelease会将对象放入自动释放池中,并返回该对象本身 //当自动释放池销毁时,将自动调用对象的release方法 Person ...
- Java文件操作 读写操作
一.Java读取文件 案例1:读取D盘的1.txt文件 编码: File file = new File("D:/1.txt"); FileReader fr = new File ...
- UIView-图层方法
// // ViewController.m // UIView-图层概念 // // Created by wangtouwang on 15/5/5. // Copyright (c) 2015年 ...
- Sumbline编译Less
Less教程 Sublime Text 2的Less2Css插件介绍与安装 网址 http://fdream.net/blog/article/783.aspx 如果出现node.exe不是内部命令的 ...
- 在Linux下不使用密码远程登陆其他Linux
有时需要再一台Linux上登陆其他Linux服务器,通常可以直接使用SSH命令,加入两台服务器一台服务器A,IP地址192.168.1.2,另一台服务器B,IP地址192.168.1.3,如果想从A服 ...
- 表格table样式布局设置
<style> table{ border-collapse:collapse; margin:0 auto;} table tr td{ border:1px solid #000; l ...
- about hadoop-eclipse-plugin used by IDE
Apache Hadoop Development Tools (HDT) is still in development phase. So, no official distribution of ...
- python 中对list做减法操作
问题描述:假设我有这样两个list, 一个是list1,list1 = [1, 2, 3, 4, 5] 一个是list2,list2 = [1, 4, 5] ...
- b+树 b-树的区别
B+树与B*树小结 一.B+树 1.B+树定义与特性 B+树是B-树的变体,也是一种多路搜索树: 其定义基本与B-树同,除了: 1).非叶子结点的子树指针与关键字个数相同: 2).非叶子结点的子树指针 ...
- zzuli oj 1145 有问题的里程表 2
Description 某辆汽车有一个里程表,该里程表可以显示一个整数,为该车走过的公里数.然而这个里程表有个毛病:它总是从3变到5,而跳过数字4,里程表所有位(个位. 十位.百位等)上的数字都是如此 ...