HDU 1251 统计难题
来源:互联网 发布:支持java的游戏引擎 编辑:程序博客网 时间:2024/06/10 07:52
纯属拿来练字典树模板的
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>using namespace std;char ch[100005][15];char str[15];int pos=0,ans=0;#define Max 26struct trie{int v;trie *next[Max];};trie *root;void init(){ trie *t,*p=root; int length=strlen(ch[pos]); for(int i=0;i<length;i++){ int id=ch[pos][i]-'a'; if(p->next[id]==NULL){ t=new trie; for(int j=0;j<26;j++){ t->next[j]=NULL; } t->v=0; p->next[id]=t; } p=p->next[id]; p->v++; }}void find(){int length=strlen(str);trie *p=root;for(int i=0;i<length;i++){int id=str[i]-'a';if(p->next[id]==NULL)break;p=p->next[id];if(i==length-1)ans+=p->v;}}int main(){ root=new trie; for(int i=0;i<26;i++){ root->next[i]=NULL; root->v=0; }while(gets(ch[pos])){ if(strlen(ch[pos])==0) break; init(); pos++;}while(scanf("%s",str)!=EOF){find();printf("%d\n",ans);ans=0;}return 0;}
0 0
- HDU 1251 统计难题
- HDU 1251 统计难题
- hdu 1251 统计难题
- HDU 1251:统计难题
- HDU 1251 统计难题
- Hdu-1251 统计难题
- hdu 1251 统计难题
- hdu 1251 统计难题
- hdu 1251 统计难题
- HDU-1251-统计难题
- HDU 1251 统计难题
- hdu 1251统计难题
- hdu 1251统计难题
- hdu 1251 统计难题
- HDU 1251 统计难题
- hdu 1251统计难题
- HDU 1251 统计难题
- hdu 1251 统计难题
- 字符串读取错误
- Java 基础 polymorphism(多态)
- 作为大型网站架构必须考虑的十大问题
- linux中mmap系统调用原理分析与实现
- 游戏服务器端开发要点
- HDU 1251 统计难题
- chapter6/c/ 下make报如下错误
- Modbus简介
- socket与http的比较
- Socket通信总结:
- cxLookupComboBox
- 数据结构之查找
- vector与迭代器
- 架构设计的UML图形思考