题意 : 输入若干个树木品种,里边有的是重复的,让你统计每个品种占输入的总数量的百分比,最后按字典序输出

思路 : 本题数量很大,所以采用直接统计的方式会超时,而采用的方法可以用二叉搜索树,或者用map函数或者是字典树都可以实现,呃,我想说,为什么用G++交WA了,得用C++交才对啊

#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std ;
struct node
{
char name[] ;
struct node *lchild,*rchild ;
int count ;//记录该结点品种出现次数
}tree ;
struct node *root ;
int n = ;
void mid(struct node *root)
{
if(root != NULL)//按照中序遍历模式计算输出就是字典序
{
mid(root->lchild) ;
printf("%s %.4lf\n",root->name,((double)(root->count)/(n*1.0))*) ;
//输出单词和所占百分比
mid(root->rchild);
}
}
void insertBST(struct node **root,char *s)
{
if(*root == NULL)
{
struct node *p = (struct node *)malloc(sizeof(tree));
strcpy(p->name,s);//品种复制给新开辟的结点
p->lchild = NULL ;
p->rchild = NULL ;
p->count = ;
*root = p ;
}
else
{
if(strcmp(s,(*root)->name) == )//出现相同品种
{
((*root)->count)++ ;//该品种数加1,并不再重复插入
return;
}
else if(strcmp(s,(*root)->name) < )//如果插入单词小于当前结点单词
insertBST(&((*root)->lchild),s);//插入当前品种左子树
else insertBST(&((*root)->rchild),s);//否则插入右子树
}
}
int main()
{
char s[];
while(gets(s)!=NULL)
{
insertBST(&root,s);
n++ ;
}
mid(root) ;
return ;
}

http://www.cnblogs.com/fanminghui/p/3272141.html

会神用map写的,代码好短....

POJ2418Hardwood Species的更多相关文章

  1. 二叉排序树:POJ2418-Hardwood Species(外加字符串处理)

    Hardwood Species Time Limit: 10000MS Memory Limit: 65536K Description Hardwoods are the botanical gr ...

  2. POJ 2418 Hardwood Species

                                                     Hardwood Species Time Limit: 10000MS   Memory Limit ...

  3. Hardwood Species 分类: POJ 树 2015-08-05 16:24 2人阅读 评论(0) 收藏

    Hardwood Species Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 20619 Accepted: 8083 De ...

  4. Hardwood Species(水)

    Time Limit:10000MS    Memory Limit:65536KB    64bit IO Format:%I64d & %I64u SubmitStatus Descrip ...

  5. POJ2418——Hardwood Species(map映射)

    Hardwood Species DescriptionHardwoods are the botanical group of trees that have broad leaves, produ ...

  6. POJ 2418 ,ZOJ 1899 Hardwood Species - from lanshui_Yang

    Description Hardwoods are the botanical group of trees that have broad leaves, produce a fruit or nu ...

  7. POJ训练计划2418_Hardwood Species(Trie树)

    解题报告 Tire树. #include <iostream> #include <cstring> #include <cstdio> #include < ...

  8. [ACM] POJ 2418 Hardwood Species (Trie树或map)

    Hardwood Species Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 17986   Accepted: 713 ...

  9. POJ2418 Hardwood Species—二叉查找树应用

    1. Hardwood Species原题描述   Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 14326   Acce ...

随机推荐

  1. [windows phone开发]新生助手的开发过程与体会一

    功能需求分析: 1.  为到达学院的新生指路,给出所有路线,并给出必要提示: 2.  对学院建筑进行介绍: 3.  对学院周边环境(交通.购物.银行等)进行介绍: 4.  必要的应用设置 总体设计: ...

  2. 9.配置postfix空客户端

    将本地邮件服务器配置充当为控客户端,已将所有邮件都转发到中央服务器以进行发送 1.postconf -e "relayhost=[mail.example.com]" 邮件被路由到 ...

  3. VmodCAM 初始化

    ; WIP Last Changed Rev: 2172 ;********************************************************************** ...

  4. 例题6-7 Trees on the level ,Uva122

    本题考查点有以下几个: 对数据输入的熟练掌握 二叉树的建立 二叉树的宽度优先遍历 首先,特别提一下第一点,整个题目有相当一部分耗时在了第一个考查点上(虽然有些不必要,因为本应该有更简单的方法).这道题 ...

  5. textarea 在光标处插入文字

    效果演示 // 欢迎访问cssfirefly.cnblogs.com html: <textarea id="text" style="width:500px;he ...

  6. rsync参数详解、利用ssh、rsync 实现数据的定时同步

    rsync 简介 rsync(remote synchronize)是一个远程数据同步工具,可通过 LAN/WAN 快速同步多台主机之间的文 件.也可以使用 rsync 同步本

  7. DataSnap中连接池的应用

    当开发人员开始创建Delphi的DataSnap应用时很常见的数据库连接定义方式是每个数据模块建立一个连接.这样做将产生大量的数据库连接,并产生很多问题.从Delphi XE开始,EMB提供了Sess ...

  8. 初级jQuery的使用

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  9. c# datatable list 相互转换

    /*Converts List To DataTable*/ public static DataTable ToDataTable<TSource>(IList<TSource&g ...

  10. Eclipse中使用javap运行配置详解

    javap是sun提供的对class文件进行反编译的工具 1.配置Run---external tools---external tools configurations 选择Program 新建ja ...