poj 2418 Hardwood Species(Trie)
来源:互联网 发布:明斯克协议 知乎 编辑:程序博客网 时间:2024/06/08 04:27
第一次做这个题用map做的,这次用字典树做的。
#include <cstdio>#include <cstring>struct Trie{ int cnt; char str[33]; Trie *next[127]; Trie() { cnt = 0; memset(next,0,sizeof(next)); }};char s[33];Trie *root;int num;void Insert(char *s){ Trie *p = root; int len = 0; while(s[len] != '\0') { int index = s[len++]; if(!p->next[index]) p->next[index] = new Trie; p = p->next[index]; } strcpy(p->str,s); p->cnt++;}void Print(Trie *p){ if(!p) return; if(p->cnt) printf("%s %.4f\n",p->str,(p->cnt/(double)num)*100); for(int i = 0; i < 127; ++i) if(p->next[i]) Print(p->next[i]);}int main(){ //freopen("in.txt","r",stdin); num = 0; root = new Trie; while(gets(s)) { Insert(s); ++num; } Print(root); return 0;}
0 0
- poj 2418 Hardwood Species(Trie)
- POJ 2418 Hardwood Species Trie解法
- poj 2418 Hardwood Species(数据结构:trie+dfs)
- poj 2418 Hardwood Species (trie 树)
- POJ 2418 Hardwood Species (trie树\map)
- poj 2418 Hardwood Species(Trie树)
- poj 2418 Hardwood Species
- POJ 2418 Hardwood Species
- poj 2418Hardwood Species
- POJ 2418 Hardwood Species
- poj 2418 Hardwood Species
- POJ 2418 Hardwood Species
- POJ 2418 Hardwood Species
- poj 2418Hardwood Species
- POJ 2418 Hardwood Species
- POJ 2418 Hardwood Species
- POJ 2418 Hardwood Species
- POJ 2418 Hardwood Species
- angular2下用http到由SpringMVC发布rest服务的服务器端拉取数据
- 常用PHP函数系列六:PHP隐藏手机号中间四位
- IP 域名 DNS之间的区别
- 【Mac】树莓派的远程访问
- 常用PHP函数系列七:生成唯一的注册码
- poj 2418 Hardwood Species(Trie)
- 【jzoj3250】【Pow】
- hust 1585 排队
- Animate.css动画库的使用
- IOS int 转nsdata (把1 变为 0 0 0 1)
- 常用PHP函数系列八:计算两个时间戳之间的日期(常用于倒计时计算时间)
- 从尾到头打印链表
- java集合详解
- shell练习1:删除目录下指定文件中的指定行