HDU --1251
统计难题
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)
Total Submission(s): 15031 Accepted Submission(s): 6436
注意:本题只有一组测试数据,处理到文件结束.
#include<cstdio>
#include<string>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
class Node{
public:
int cnt;
Node *child[];
Node(){
cnt =;
for(int i = ;i < ;i ++)
child[i] = NULL;
}
};
Node *root = new Node();
void Update(char *str){
Node *tmp = root;
while(*str != '\0'){
if(tmp->child[*str - 'a'] == NULL){
Node *p = new Node();
tmp->child[*str - 'a'] = p;
}
tmp = tmp->child[*str - 'a'];
tmp->cnt++;
str++;
}
}
int Getresult(char *str){
Node *tmp = root;
while(*str != '\0'){
if(tmp->child[*str - 'a'] == NULL) return ;
tmp = tmp->child[*str - 'a'];
str++;
}
return tmp->cnt;
}
int main(){
char str[];
while(cin.getline(str,) && strcmp(str,"")) Update(str);
while(~scanf("%s",str)) printf("%d\n",Getresult(str));
return ;
}
HDU --1251的更多相关文章
- hdu 1251 统计难题 (字典树入门题)
/******************************************************* 题目: 统计难题 (hdu 1251) 链接: http://acm.hdu.edu. ...
- HDU 1251 Trie树模板题
1.HDU 1251 统计难题 Trie树模板题,或者map 2.总结:用C++过了,G++就爆内存.. 题意:查找给定前缀的单词数量. #include<iostream> #incl ...
- HDU 1251 统计难题(Trie模版题)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others) Total Subm ...
- hdu 1251 统计难题(trie 树的简单应用)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意:给你多个字符串,求以某个字符串为前缀的字符串数量. 思路:简单的trie数应用,在trie ...
- hdu 1251(字典树)
题目链接:http://acm.hdu.edu.cn/status.php?user=NYNU_WMH&pid=1251&status=5 Trie树的基本实现 字母树的插入(Inse ...
- HDU 1251 统计难题(字典树模板题)
http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意:给出一些单词,然后有多次询问,每次输出以该单词为前缀的单词的数量. 思路: 字典树入门题. #inc ...
- HDU 1251:统计难题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意不难理解,就是先输入不知道多少个字符串,然后用一个空行结束这个输入,然后接下来不知道多少行再 ...
- hdu 1251 统计难题(字典树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1251 统计难题 Time Limit: 4000/2000 MS (Java/Others) M ...
- 字典树 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 ...
随机推荐
- 菜鸟笔记之java中方法使用
N!!!java中无参无返回值方法的使用 1,定义方法 eg: public void show(){ System.out.println("HelloWorld!") } -- ...
- skip跳跃表的实现
skiplist介绍 跳表(skip List)是一种随机化的数据结构,基于并联的链表,实现简单,插入.删除.查找的复杂度均为O(logN).跳表的具体定义, 跳表是由William Pugh发明的, ...
- leetcode problem 32 -- Longest Valid Parentheses
Longest Valid Parentheses Given a string containing just the characters '(' and ')', find the length ...
- linux进程间通信--有名管道
有名管道 只有当一个库函数失败时,errno才会被设置.当函数成功运行时,errno的值不会被修改.这意味着我们不能通过测试errno的值来判断是否有错误存在.反之,只有当被调用的函数提示有错误发生时 ...
- 相看系统中用户的信息 passwd, shadow
用用户的信息都保存在 etc/passwd 和 etc/shadow 文件中,其中 shadow 保存的是经过加密码的 能过 cat etc/passwd 和 cat etc/shadow 来查看相关 ...
- 不能正确获得上次构建以来的Commit
不能正确获得上次构建以来的Commit 如何解决?
- js实现幻灯片播放图片示例代码
幻灯片播放图片的效果想必大家都有见到过吧,下面有个不错的示例,感兴趣的朋友可以参考下 复制代码代码如下: <select id="img_date" style=" ...
- 网络编程TCP/IP实现客户端与客户端聊天
一.TCP/IP协议 既然是网络编程,涉及几个系统之间的交互,那么首先要考虑的是如何准确的定位到网络上的一台或几台主机,另一个是如何进行可靠高效的数据传输.这里就要使用到TCP/IP协议. TCP/I ...
- Leetcode 解题 Median of Two sorted arrays
题目:there are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the ...
- xcode 自动添加注释,生成文档
一.自动生成注释代码 添加一个快捷键,生成 注释代码 ThisService 下载连接:http://wafflesoftware.net/thisservice/ ...