HDOJ ——统计难题
统计难题
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)
Total Submission(s): 16498 Accepted Submission(s): 7091
注意:本题只有一组测试数据,处理到文件结束.
band
bee
absolute
acm
ba
b
band
abc
3
1
0
#include <stdio.h>
#include <malloc.h>
#include <string.h>
struct node
{
int val;
node *next[26];
};
node *root;
int getid(char s){return s-'a';}
void insert(char *s)
{
int len = strlen(s),i;
node *pre = root,*next;
for(i=0;i<len;i++)
{
int id = getid(s[i]);
next = pre->next[id];
if(!next)
{
next = (node*)malloc(sizeof(node));
memset(next,0,sizeof(node));
pre->next[id] = next; }
next->val++;
pre = next;
}
} int query(char *s)
{
int i,len = strlen (s);
node *pre = root,*next;
for(i =0;i<len;i++)
{
int id = getid(s[i]);
next = pre->next[id];
if(!next)
return 0;
pre= next;
}
return pre->val;
}
char s[26];
int main()
{
root = (node*)malloc(sizeof(node));
memset(root,0,sizeof(node));
while(gets(s)&&strlen(s))
{
insert(s);
}
while(gets(s))
{
printf("%d\n",query(s));
}
return 0;
}
HDOJ ——统计难题的更多相关文章
- 统计难题 HDOJ --1251
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- 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统计难题
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- hdu 1251 统计难题 (字典树入门题)
/******************************************************* 题目: 统计难题 (hdu 1251) 链接: http://acm.hdu.edu. ...
- hdu1251 统计难题
地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=1251 题目: 统计难题 Time Limit: 4000/2000 MS (Java/Othe ...
- hdu 1251:统计难题(字典树,经典题)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- ACM:统计难题 解题报告-字典树(Trie树)
统计难题 Time Limit:2000MS Memory Limit:65535KB 64bit IO Format:%I64d & %I64u Submit Status ...
- HDU 1251 统计难题(Trie模版题)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others) Total Subm ...
随机推荐
- 【Search a 2D Matrix】cpp
题目: Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the f ...
- Leetcode#61 Rotate List
原题地址 我一直不太理解为什么叫rotate,翻译成"旋转"吧,似乎也不像啊.比如: 1->2->3->4->5->NULL 向右旋转2的距离,变成了 ...
- Somebody That I Used to Know
一.查看歌词 http://baike.baidu.com/view/7925491.htm 二.考量歌词 1.我告诉自己你就是我的挚爱 但你的陪伴却让我倍感孤单 但那就是爱 让我刻骨铭心难以忘怀 既 ...
- Web流程
Web阻塞加载,异步加载. 延迟执行,立即执行. 加载并执行,不要调用代码. 加载并执行时会调用代码,但是加载并执行时不要调用代码,否则会改变逻辑. 上面是Web流程,JS只是web的一部分.如果关注 ...
- CodeForces 321A
A. Ciel and Robot time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- 异步JS:$.Deferred的使用
异步JS:$.Deferred的使用 原文链接:http://www.html5rocks.com/en/tutorials/async/deferred/ 当我们构建一个平稳的,响应式的HTML5应 ...
- POJ 1274
#include<iostream> #include<stdio.h> #include <string.h> #include <vector> # ...
- Java IO(三)
File File类的常见方法: 1.创建. boolean createNewFile():在指定位置创建文件,如果该文件已经存在,则不创建,返回false.和输出流不一样,输出流对象一建立就创建文 ...
- linux中的磁盘的MBR记录详解
在硬盘中,硬盘的0柱面0磁头第一个1扇区称为主引导扇区,也叫主引导记录-MBR(main boot record),其中MBR是以下三个部分组成 1.Bootloader,主引导程序---446个字节 ...
- lintcode:打劫房屋II
题目 打劫房屋II 在上次打劫完一条街道之后,窃贼又发现了一个新的可以打劫的地方,但这次所有的房子围成了一个圈,这就意味着第一间房子和最后一间房子是挨着的.每个房子都存放着特定金额的钱.你面临的唯一约 ...