POJ 2418 Hardwood Species
2013-08-19 21:06
369 查看
字典树 或者 map......
map 8000+ ms
View Code
map 8000+ ms
#include<stdio.h> #include<stdlib.h> #include<string.h> int max; struct T { char name[40]; int sum,mark; struct T *r,*l; }; void init(struct T *root) { root->r = NULL; root->l = NULL; root->sum = 0; root->mark = 1; } void link(struct T *p,char *temp) { if(p->mark) { strcpy(p->name,temp); p->sum++; p->mark = 0; } else { int mark = strcmp(temp,p->name); if(!mark) p->sum++; else if(mark > 0) { if(p->l != NULL) { link(p->l,temp); return; } else { struct T *t; t = (struct T *)malloc(sizeof(struct T)); init(t); p->l = t; link(p->l,temp); return; } } else if(mark < 0) { if(p->r != NULL) { link(p->r,temp); return; } else { struct T *t; t = (struct T *)malloc(sizeof(struct T)); init(t); p->r = t; link(p->r,temp); return; } } } } void output(struct T *root) { if(root->r != NULL) { output(root->r); printf("%s %.4lf\n",root->name,100.0*root->sum/max); } else printf("%s %.4lf\n",root->name,100.0*root->sum/max); if(root->l != NULL) { output(root->l); } } int main() { struct T *root; root = (struct T *)malloc(sizeof(struct T)); init(root); char temp[40]; max = 0; while(gets(temp) != NULL) { max++; link(root,temp); } output(root); return 0 ; }
View Code
相关文章推荐
- POJ 2418 Hardwood Species
- poj 2418 Hardwood Species(Trie树)
- POJ---2418-Hardwood Species(字典树)
- (使用STL自带的排序功能7.1.1)POJ 2418 Hardwood Species(map的定义、访问、迭代)
- poj 2418 Hardwood Species
- POJ2418——Hardwood Species(map映射)
- 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 (字典树 || map)
- POJ2418 Hardwood Species
- POJ 2418 Hardwood Species (trie树\map)
- POJ 2418 Hardwood Species(STL在map应用)
- poj 2418 Hardwood Species
- [ACM] POJ 2418 Hardwood Species (Trie树或map)
- POJ 2418 Hardwood Species(二叉排序树)
- POJ 2418 ,ZOJ 1899 Hardwood Species - from lanshui_Yang