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 ...
随机推荐
- autorelease 的基本使用
5-autorelease 的基本使用 0,引入 Person *p = [Persom new];[p release]; [p run]; [p run]; // 希望不立即释放,待 run执行完 ...
- Http上传文件
public class UpLoadFile { public static void UpLoadFiles(string fileName) { string fileType = Path.G ...
- CSS Masking(翻译)
原文地址:http://www.html5rocks.com/en/tutorials/masking/adobe/ 关于计算机图形,两种常见的操作是:cliping(裁剪) and masking ...
- Ubuntu下VIM(GVIM)环境配置
GVIM安装( Ubuntu自带VIM ): 通过应用商店安装或者通过以下安装. sudo apt-get install vim-gnome GVIM配置: 在 家目录 ( ~/ ) 下建立 .vi ...
- JavaScript学习总结【12】、JS AJAX应用
1.AJAX 简介 AJAX(音译为:阿贾克斯) = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML),是指一种创建交互式网页应用的网页开发技 ...
- Linux自动备份MySQL数据库脚本代码
下面这段Linux的Shell脚本用于每日自动备份MySQL数据库,可通过Linux的crontab每天定时执行 在脚本中可设置需要备份的数据库表清单,并且会将备份文件通过gzip压缩.需要注意的是, ...
- node开子线程模块--tagg2
tagg2包同样具有tagg包的多线程功能,采用新的node-gyp命令进行编译,同时它跨平台支持,mac,linux,windows下都可以使用,对开发人员的api也更加友好.安装方法很简单,直接n ...
- win7如何完全写在iis
在前些天,因为需要搭建了ftp服务器,但是今天不需要了,所以要卸载iis,因为我不会让iis和apache同时共存,所以只能卸载了 先找到windows功能,然后把Internet信息服务勾选掉,重启 ...
- Android自定义图片加载框架
大神原网址: http://blog.csdn.net/lmj623565791/article/details/41874561 思路: 1. 压缩图片 压缩本地图片: 获得imageview想要 ...
- KEIL4.12中添加ULINK2的支持
转载自:http://www.amobbs.com/thread-4767650-1-1.html 如果你用KEIL4.12,但却没有Ulink2下载器,只有早先用的Ulink下载器,那么你按照下面三 ...