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 ...
随机推荐
- 如何在Angular2中使用jquery
首先在index.html中引入jquery文件 <script src="http://cdn.bootcss.com/jquery/2.1.3/jquery.js"> ...
- 对称密码-分组密码-AES
AES产生背景: DES的安全性和应用前景受到挑战,因此需要设计一个高保密性能的.算法公开的.全球免费使用的分组密码算法,用于保护敏感信息,并希望以此新算法取代DES算法,称为新一代数据加密标准,取名 ...
- IOS 学习笔记 2015-03-22 OC-API-日期
一 API 1 NSdate 2 NSDateFormatter 二 适用场景 1 获取当前日期 2 增加时间差 3 比较时间差 4 返回较早时间 5 日期格式话 6 日期转字符串 7 字符串转日期 ...
- 菜鸟的MySQL学习笔记(五)
7.自定义函数 用户自定义函数(user-defined function,UDF)是一种对MySQL扩展的途径,其用法与内置函数相同.包含了两个必要条件,参数与返回值.没有必然内在联系. 函数可以返 ...
- 通过telnet使用smtp协议发送邮件
smtp协议是一个简单的邮件传输协议,利用它我们可以将邮件发送给别人,这里将通过telnet这个程序利用smtp协议从网易向gmail发送一封邮件 网上不少有说使用telnet发送邮件的文章,我也看过 ...
- c#简单的Json解析类
使用方法: 引用Newtonsoft.Json.dll文件,然后引用命名空间using Newtonsoft.Json.Linq;JsonDome中有实例,照做就行 现在贴上示例代码 using Ne ...
- 为 DataGridView 控件添加行号
虽然好像不经常用到,不过还是记下来防止以后用到 /// <summary> /// 为 DataGridView 控件添加行号 /// </summary> /// <p ...
- hbuider 中点击就显示出一个单选的列表 ,然后后台跨域向里面动态添加数据,注意里面的格式是json object
jsp页面: <li class="mui-table-view-cell" onclick="showActionSheet()"> <di ...
- javascript笔记之正则表达式
1.在js正则表达式特殊的需要转义的字符有: ^ $ . * + ? = ! : | \ / ( ) [ ] { } 但实际应用中,还要根据实际情况来判断,以上字符可能不需要转义,也可能不止以上字符 ...
- cocos2d-x笔记2: 编译到安卓的步骤与注意事项
博客地址: www.cnblogs.com/wolfred7464/ 不得不说,真心复杂,本篇博客总结的基本是最简最直接的步骤了,不用Cygwin和Ant的,当然用也可以... 以下用 %PROJEC ...