SDUT 3375 数据结构实验之查找三:树的种类统计
数据结构实验之查找三:树的种类统计
Problem Description
随着卫星成像技术的应用,自然资源研究机构可以识别每一个棵树的种类。请编写程序帮助研究人员统计每种树的数量,计算每种树占总数的百分比。
Input
输入一组测试数据。数据的第1行给出一个正整数N (n <= 100000),N表示树的数量;随后N行,每行给出卫星观测到的一棵树的种类名称,树的名称是一个不超过20个字符的字符串,字符串由英文字母和空格组成,不区分大小写。
Output
按字典序输出各种树的种类名称和它占的百分比,中间以空格间隔,小数点后保留两位小数。
Example Input
2
This is an Appletree
this is an appletree
Example Output
this is an appletree 100.00%
DQE:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; struct Tree
{
char name[];
int n;
Tree *lt,*rt;
}; void insert(Tree *&root,char *e)
{
if(!root)
{
Tree *r=new Tree;
strcpy(r->name,e);
r->n=;
r->lt=r->rt=NULL;
root=r;
}
else
{
int cmp=strcmp(e,root->name);
if(cmp<)
insert(root->lt,e);
else if(cmp>)
insert(root->rt,e);
else
root->n++;
}
} int n;
void mout(Tree *root)
{
if(root)
{
mout(root->lt);
printf("%s %.2f%%\n",root->name,root->n*100.0/n);
mout(root->rt);
}
} int main()
{
int t;
scanf("%d\n",&t);
n=t;
Tree *root=NULL;
while(t--)
{
char ch,e[];
int i=;
while(ch=getchar(),ch!='\n')
{
if(ch>='A'&&ch<='Z')
e[i]=ch+;
else
e[i]=ch;
i++;
}
e[i]='\0';
insert(root,e);
}
mout(root);
return ;
} /***************************************************
User name: ***
Result: Accepted
Take time: 0ms
Take Memory: 156KB
Submit time: 2016-11-29 17:54:17
****************************************************/
SDUT 3375 数据结构实验之查找三:树的种类统计的更多相关文章
- SDUT-3375_数据结构实验之查找三:树的种类统计
数据结构实验之查找三:树的种类统计 Time Limit: 400 ms Memory Limit: 65536 KiB Problem Description 随着卫星成像技术的应用,自然资源研究机 ...
- SDUT 3374 数据结构实验之查找二:平衡二叉树
数据结构实验之查找二:平衡二叉树 Time Limit: 400MS Memory Limit: 65536KB Submit Statistic Problem Description 根据给定的输 ...
- SDUT 3311 数据结构实验之串三:KMP应用
数据结构实验之串三:KMP应用 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 有n个小朋友 ...
- SDUT 3347 数据结构实验之数组三:快速转置
数据结构实验之数组三:快速转置 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 转置运算是一 ...
- SDUT OJ 数据结构实验之二叉树三:统计叶子数
数据结构实验之二叉树三:统计叶子数 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descr ...
- SDUT OJ 数据结构实验之串三:KMP应用
数据结构实验之串三:KMP应用 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descrip ...
- SDUT OJ 数据结构实验之排序三:bucket sort
数据结构实验之排序三:bucket sort Time Limit: 250 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem D ...
- SDUT OJ 数据结构实验之链表三:链表的逆置
数据结构实验之链表三:链表的逆置 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descri ...
- SDUT 3400 数据结构实验之排序三:bucket sort
数据结构实验之排序三:bucket sort Time Limit: 150MS Memory Limit: 65536KB Submit Statistic Problem Description ...
随机推荐
- awk---Linux下文本处理五大神器之二
转自:http://www.cnblogs.com/dong008259/archive/2011/12/06/2277287.html awk是一个非常棒的数字处理工具.相比于sed常常作用于一整行 ...
- hdu 1937 Finding Seats
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...
- 《Javascript高级程序设计》阅读记录(三):第五章 上
这个系列以往文字地址: <Javascript高级程序设计>阅读记录(一):第二.三章 <Javascript高级程序设计>阅读记录(二):第四章 这个系列,我会把阅读< ...
- RabbitMQ集群 Docker一键部署
以下内容来自网络转载 步骤1. 安装docker 以centos7为例,https://docs.docker.com/engine/installation/linux/centos/ 步骤2. 创 ...
- Windbg内核调试之三: 调试驱动
这次我们通过一个实际调试驱动的例子,来逐步体会Windbg在内核调试中的作用.由于条件所限,大多数情况下,很多人都是用VMware+Windbg调试内核(VMware的确是个好东西).但这样的调试需要 ...
- 洛谷【P2024】[NOI2001]食物链
浅谈并查集:https://www.cnblogs.com/AKMer/p/10360090.html 题目传送门:https://www.luogu.org/problemnew/show/P202 ...
- SpringCloud微服务实战——第二章Springboot
Spring Boot项目工程 src/main/java:主程序入口HelloApplication,可以通过直接运行该类来启动Spring Boot应用. src/main/resources:配 ...
- Python collections系列之可命名元组
可命名元组(namedtuple) 根据nametuple可以创建一个包含tuple所有功能以及其他功能的类 1.创建一个坐标类 import collections # 创建类, defaultd ...
- CountDownLatch和cyclicbarrier的使用
CountDownLatch: 一个同步辅助类,在完成一组正在其他线程中执行的操作之前,它允许一个或多个线程一直等待. 用给定的计数初始化 CountDownLatch.由于调用了 countDown ...
- List的使用1(两张表或者一张表的自身关系)
第一,在Model中 首先,在视图Model(GZUModel)中定义一个SelectListItem集合 public List<SelectListItem> AList { get; ...