POJ 2001 TRIE
来源:互联网 发布:淘宝会员名字能改吗 编辑:程序博客网 时间:2024/06/15 23:19
<pre name="code" class="delphi">#include"stdio.h"#include"iostream"#include"string.h"#include"stdlib.h"using namespace std;const int maxn=20*1000+20;const int max_sigma=26;const int max_len=30;char s[1000+20][max_len];struct trie{ int node[maxn][max_sigma]; int val[maxn]; int cnt; void init(){cnt=1;memset(node[0],0,sizeof(node[0]));memset(val,0,sizeof(val));} //初始化 节点数为1 根节点 计数数组 int idx(char c){return c-'a';} void insert(char *s) { int p=0,k; for(int i=0;s[i];i++) { int k=idx(s[i]); if(!node[p][k]) { memset(node[cnt],0,sizeof(node[cnt])); //新建一个节点 node[p][k]=cnt++; } p=node[p][k]; //移动到子节点 val[p]++; //这种前缀的数量加+1 } } int find(char *S) //反值为 字符串的下标 { int k; int p=0; int i; int len=strlen(S); for(i=0;S[i];i++) { k=idx(S[i]); if(val[node[p][k]]==1) return i; //当这种前缀只出现一次说明就是最短前缀 p=node[p][k]; } return len-1; //当没有这种前缀 }};int main(){ //freopen("a.txt","r",stdin); int n; char tmp[max_len]; int i,j; trie a; a.init(); int cnt=0; while(scanf("%s",s[cnt])!=EOF) { a.insert(s[cnt]);cnt++; } for(i=0;i<cnt;i++) { printf("%s ",s[i]); int pos=a.find(s[i]); for(j=0;j<=pos;j++) putchar(s[i][j]); puts(""); } return 0;}
0 0
- POJ 2001 Trie树
- poj 2001 trie 树
- poj 2001(trie)
- poj 2001(trie)
- POJ 2001 TRIE
- poj 2001 Trie树
- POJ 2001 Trie 字典树
- POJ 2001 trie字典树
- poj 2001 Shortest Prefixes(Trie)
- poj 2001 Shortest Prefixes trie
- poj 2001 Shortest Prefixes Trie
- POJ 2001 Shortest Prefixes // Trie
- [poj 2001]Shortest Prefixes [Trie]
- zoj 2346 || poj 2001 Shortest Prefixes(Trie~!)
- poj 2001 Shortest Prefixes Trie树
- POJ-2001(trie字典树)
- Trie 字典树 poj 2001 示例
- Trie 字典树 poj 2001 示例
- 图解C++的多态思想
- elasticsearch集群部署安装
- lightoj 1038 概率dp
- 正则表达式验证
- java集合类
- POJ 2001 TRIE
- windows下python配置numpy、matplotlib、scipy
- 新公司一个月的感受
- CSS预处理-LESS
- android跨平台开发系列之-使用webview和JS调用(二)
- ActionScript 3.0 学习(十七) away3D学习2 away3d的贴图原理
- 关于用ss代理
- Linux基础学习1
- Python 字符串操作