HDOJ1251 统计难题(字典树)
来源:互联网 发布:上海质检院待遇知乎 编辑:程序博客网 时间:2024/06/06 00:05
WA了,回头找错。。。
#include<iostream>#include<string.h>using namespace std;#define maxn 26struct node{ int num; node *next[maxn];};node *root;node *build(){ node *p=new node; p->num=1; for(int i=0;i<maxn;i++) p->next[i]=NULL; return p;}void insert(char *s){ node *p=root; int len=strlen(s); for(int i=0;i<len;i++){ if(p->next[s[i]-'a']!=NULL){ p=p->next[s[i]-'a']; p->num++; } else{ p->next[s[i]-'a']=build(); p=p->next[s[i]-'a']; p->num=1; } }}int search(char *s){ node *p=root; int len=search(s); for(int i=0;i<len;i++){ if(p->next[s[i]-'a']==NULL) return 0; else p=p->next[s[i]-'a']; } return p->num;}int main(){ char s1[11],s2[11]; root=build(); while(gets(s1) && strcmp(s1,"")!=0){//strcmp比较两个字符串的大小 insert(s1); } while(gets(s2)!=NULL){ int cnt=search(s2); cout<<cnt<<endl; } return 0;}
阅读全文
0 0
- HDOJ1251 统计难题(字典树)
- 统计难题(hdoj1251)
- 入门字典树 HDOJ1251 统计难题 HDOJ1075 字典翻译
- HDOJ1251-统计难题(trie树入门)
- HDOJ1251 统计难题 Trie树的基本操作
- 统计难题(字典树)
- 统计难题(字典树)
- 统计难题 (字典树)
- 统计难题(字典树)
- 统计难题【字典树】
- 统计难题 字典树
- 统计难题(字典树)
- hdu1251 统计难题(字典树)
- HDU 1251统计难题(字典树)
- 统计难题(字典树的应用)
- hdu 1251 统计难题(字典树)
- hdu 1251 统计难题(字典树)
- hdu1251统计难题(字典树)
- 自行装配适合深度学习的电脑
- 常见开发安全规避和敏感信息处理
- 某安全浏览器竟然也被查出高危漏洞?开源安全问题不容忽视
- 数据仓库架构
- NodeJS 异步 async / await 方案
- HDOJ1251 统计难题(字典树)
- Mac环境变量配置书写格式
- linux iptables常用命令之配置生产环境iptables及优化
- Android Studio 入门级教程
- Android自动化测试之Monkey工具
- HDU 1686
- 《MySQL入门很简单》学习笔记(16)之第16章数据备份与还原(关键词:MySQL/数据备份/数据还原)
- 9.9 天平问题 2720
- BZOJ:3441 乌鸦喝水