zoukankan      html  css  js  c++  java
  • SDUT 3375 数据结构实验之查找三:树的种类统计

    数据结构实验之查找三:树的种类统计

    Time Limit: 400MS Memory Limit: 65536KB

    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:

     
    二叉排序树的应用,全转换为小写就AAAC了233
     
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 using namespace std;
     5 
     6 struct Tree
     7 {
     8     char name[24];
     9     int n;
    10     Tree *lt,*rt;
    11 };
    12 
    13 void insert(Tree *&root,char *e)
    14 {
    15     if(!root)
    16     {
    17         Tree *r=new Tree;
    18         strcpy(r->name,e);
    19         r->n=1;
    20         r->lt=r->rt=NULL;
    21         root=r;
    22     }
    23     else
    24     {
    25         int cmp=strcmp(e,root->name);
    26         if(cmp<0)
    27             insert(root->lt,e);
    28         else if(cmp>0)
    29             insert(root->rt,e);
    30         else
    31             root->n++;
    32     }
    33 }
    34 
    35 int n;
    36 void mout(Tree *root)
    37 {
    38     if(root)
    39     {
    40         mout(root->lt);
    41         printf("%s %.2f%%
    ",root->name,root->n*100.0/n);
    42         mout(root->rt);
    43     }
    44 }
    45 
    46 int main()
    47 {
    48     int t;
    49     scanf("%d
    ",&t);
    50     n=t;
    51     Tree *root=NULL;
    52     while(t--)
    53     {
    54         char ch,e[24];
    55         int i=0;
    56         while(ch=getchar(),ch!='
    ')
    57         {
    58             if(ch>='A'&&ch<='Z')
    59                 e[i]=ch+32;
    60             else
    61                 e[i]=ch;
    62             i++;
    63         }
    64         e[i]='';
    65         insert(root,e);
    66     }
    67     mout(root);
    68     return 0;
    69 }
    70 
    71 /***************************************************
    72 User name: ***
    73 Result: Accepted
    74 Take time: 0ms
    75 Take Memory: 156KB
    76 Submit time: 2016-11-29 17:54:17
    77 ****************************************************/
  • 相关阅读:
    BZOJ1841 : 蚂蚁搬家
    BZOJ3068 : 小白树
    BZOJ4449 : [Neerc2015]Distance on Triangulation
    BZOJ3692 : 愚蠢的算法
    BZOJ3145 : [Feyat cup 1.5]Str
    BZOJ4684 : Company Organization
    BZOJ2934 : [Poi1999]祭坛问题
    ML(2)——感知器
    ML(附录1)——梯度下降
    微服务架构
  • 原文地址:https://www.cnblogs.com/Leroscox/p/6114640.html
Copyright © 2011-2022 走看看