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

思路 : 本题数量很大,所以采用直接统计的方式会超时,而采用的方法可以用二叉搜索树,或者用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. java中对集合对象list的几种循环访问

    java中对集合对象list的几种循环访问的总结如下 1 经典的for循环 public static void main(String[] args) { List<String> li ...

  2. c++11:copy_n

    copy_n: Copies exactly count values from the range beginning at first to the range beginning at resu ...

  3. 锋利的jquery-DOM操作

    1 查找节点 ① 可根据jquery选择器来完成节点查找 ② 可用.text()获取节点的文本内容 ③ 可用.attr("attr")获取属性value 2 创建节点 ① 可用jq ...

  4. 9更令人兴奋的WebGL演示

    Firefox OS,asm.js和推动浏览器性能改进,画布和WebGL技术是打开一个世界的可能性.我上9令人兴奋的帆布演示,然后把它与9 WebGL演示,但我想超越这篇文章.我发现9个更多的精神We ...

  5. Android混淆问题

    最近做了2个项目,全部要混淆,刚接触,自己在网上找了还多资料,感觉各有千秋,自己总结了一下,第一次发帖,不喜勿喷.求各种指导!!! android应用程序的混淆打包规范 1.在工程文件project. ...

  6. java 环境变量设置

    JAVA_HOME  C:\Program Files\Java\jdk1.7.0 PATH %JAVA_HOME%\bin;%JAVA_HOME%\jre\bin; CLASSPATH .;%JAV ...

  7. css透明(支持各浏览器)

    opacity: 0.4;filter: progid:DXImageTransform.Microsoft.Alpha(opacity=40); -ms-filter: "progid:D ...

  8. windows创建桌面快捷方式的VBA脚本

    Dim wShell, oShortcut    'Dim strDesktop$ ' 为了与VBS兼容,    Dim strDesktop    ' 这里改写一下,测试通过...    Set w ...

  9. 使用virtualenv或zc.buildout创建Python-tornado分离环境

    originally created by shuliang under CC BY-NC-ND 3.0 license 一.引言 学习编程,好比练功,总得先有个环境,搭台子是必须的.为了照顾初学者, ...

  10. Configure Log Shipping

    准备工作 两台装有的Windows Server 2012R2以及SQL Server 2012的服务器 下载评估版 Windows Server 2012 R2 下载 Microsoft SQL S ...