【POJ】2418 Hardwood Species
2014-06-27 12:11
351 查看
简单字典树。
#include <cstdio> #include <cstring> #include <cstdlib> #define MAXN 128 typedef struct Trie { int count; Trie *next[MAXN]; Trie() { count = 0; for (int i=0; i<MAXN; ++i) next[i] = NULL; } } Trie; Trie root; char buf[35]; double n = 0; void create(char str[]) { int i = 0, id; Trie *p = &root, *q; while (str[i]) { id = str[i]; ++i; if (p->next[id] == NULL) { q = new Trie(); p->next[id] = q; } p = p->next[id]; } p->count++; } void dfs(Trie *t, int d) { int i; if (t->count) { buf[d] = '\0'; printf("%s %.4lf\n", buf, t->count*100.0/n); } for (i=0; i<MAXN; ++i) { if (t->next[i]) { buf[d] = i; dfs(t->next[i], d+1); } } } int main() { while (gets(buf) != NULL) { create(buf); n += 1.0; } dfs(&root, 0); return 0; }
相关文章推荐
- POJ-2418-Hardwood Species-字典树
- poj - 2418 Hardwood Species
- poj2418Hardwood Species
- poj2418Hardwood Species
- poj 2418 Hardwood Species
- POJ 2418 Hardwood Species( AVL-Tree )
- poj 2418Hardwood Species
- poj 2418 Hardwood Species--tire
- poj 2418 Hardwood Species(Trie)
- [ACM] POJ 2418 Hardwood Species (Trie树或者map)
- POJ 2418 Hardwood Species (trie树\map)
- poj 2418 Hardwood Species(二叉排序树||map迭代器)
- POJ 2418 Hardwood Species( AVL-Tree )
- poj 2418 Hardwood Species
- POJ 2418 Hardwood Species(map)
- [ACM] POJ 2418 Hardwood Species (Trie树或map)
- POJ训练计划2418_Hardwood Species(Trie树)
- POJ 2418-Hardwood Species(map)
- poj 2418 Hardwood Species 快排
- POJ 2418 Hardwood Species【字典树 / map】