poj2418Hardwood Species
2013-01-20 15:45
483 查看
http://poj.org/problem?id=2418
trie树,有非空格、字母的字符
View Code
trie树,有非空格、字母的字符
View Code
#include <iostream> #include<cstdio> #include<cstring> #include<stdlib.h> #include<algorithm> using namespace std; typedef struct node { int num; struct node *next[130]; node() { memset(next,NULL,sizeof(next)); num = 0; } }trie; int y,k; char ss[10010][40],w[40]; void ctrie(trie *t,char *x) { int i,j,d,k = strlen(x); char yy[40]; strcpy(yy,x); trie *p = t; for(i = 0 ; i < k ; i++) { d = x[i]; if(p->next[d]==NULL) { p->next[d] = new node; } p = p->next[d]; } if(p->num==0) { strcpy(ss[y],yy); y++; } p->num++; } void dfs(trie *t,int x) { trie *p = t; int i; if(p->num>0) { w[x] = '\0'; printf("%s %.4lf\n",w,p->num*100.0/k); } for(i = 1; i <= 129 ; i++) { if(p->next[i]!=NULL) { w[x] = i; dfs(p->next[i],x+1); } } } int main() { int i,j; char s[40]; trie *t = new node; while(gets(s)!=NULL) { k++; ctrie(t,s); } dfs(t,0); return 0; }
相关文章推荐
- POJ-2418 Hardwood Species
- POJ 2418 Hardwood Species (字典树 || map)
- POJ 2418 ,ZOJ 1899 Hardwood Species - from lanshui_Yang
- POJ-2418-Hardwood Species-字典树
- poj 2418 Hardwood Species(二分)
- poj 2418Hardwood Species
- [ACM] POJ 2418 Hardwood Species (Trie树或map)
- POJ 2418 Hardwood Species(二叉排序树)
- POJ2418 Hardwood Species
- POJ 2418 Hardwood Species (trie树\map)
- POJ 2418 Hardwood Species(STL在map应用)
- poj 2418 Hardwood Species
- POJ2418——Hardwood Species
- poj_2418 Hardwood Species (字典序Trie树)
- poj - 2418 Hardwood Species
- poj 2418 Hardwood Species(二叉排序树||map迭代器)
- POJ 2418 Hardwood Species【字典树 / map】
- POJ 2418 Hardwood Species (二叉搜索树/map)
- POJ 2418 Hardwood Species【二叉查找树】
- POJ 2418 Hardwood Species(map)