7-24 Tree species statistics (25 points) (Application of binary sorting)

Source: Internet
Author: User

With the application of satellite imaging technology, natural resources research institutions can identify the species of each tree. Please write a program to help researchers count the number of each tree, and calculate the percentage of each tree as a total.

Input format:

The input first gives a positive integer n (≤10?). 5?? ), followed by n rows, each giving the name of the species of a tree observed by the satellite. The category name consists of no more than 30 English letters and spaces (case insensitive).

Output format:

Increments the type name of each tree and the percentage of its total as a dictionary increment, separated by a space, and retains 4 digits after the decimal point.

Input Sample:
29Red AlderAshAspenBasswoodAshBeechYellow BirchAshCherryCottonwoodAshCypressRed ElmGumHackberryWhite OakHickoryPecanHard MapleWhite OakSoft MapleRed OakRed OakWhite OakPoplanSassafrasSycamoreBlack WalnutWillow
Sample output:
Ash 13.7931%Aspen 3.4483%Basswood 3.4483%Beech 3.4483%Black Walnut 3.4483%Cherry 3.4483%Cottonwood 3.4483%Cypress 3.4483%Gum 3.4483%Hackberry 3.4483%Hard Maple 3.4483%Hickory 3.4483%Pecan 3.4483%Poplan 3.4483%Red Alder 3.4483%Red Elm 3.4483%Red Oak 6.8966%Sassafras 3.4483%Soft Maple 3.4483%Sycamore 3.4483%White Oak 10.3448%Willow 3.4483%Yellow Birch 3.4483%
1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4 5typedefstructTnode *Position;6 typedef Position Bintree;7 structTnode8 {9     Chardata[ *];Ten Bintree left; One Bintree right; A     intcount; - }; -Bintree Insert (Bintree BT,Charname[]); the voidPrint (Bintree BT,intn); - intMain () - { -     intN; +     inti; -Bintree BT =NULL; +  Ascanf"%d",&n); at GetChar (); -      for(i=0; i<n; i++){ -         Charname[ *]; - gets (name); -BT =Insert (bt,name); -     } in Print (BT, n); -  to     return 0; + } -  the  *Bintree Insert (Bintree BT,Charname[]) $ {Panax Notoginseng     if( !BT) { -BT = (bintree)malloc(sizeof(structtnode)); thestrcpy (bt->data,name); +Bt->count=1; ABt->left = Bt->right =NULL; the     } +     Else{ -         intA = strcmp (bt->data,name); $         if(a<0) Bt->right = Insert (bt->right,name); $  -         Else if(a>0) Bt->left=insert (bt->left,name); -         Elsebt->count++; the     } -     returnBT;Wuyi } the  - voidPrint (Bintree BT,intN) Wu { -     if( ! BT)return; About     Else{ $Print (bt->left,n); -printf"%s",bt->data); -printf"%.4f%%\n",(Double) bt->count/n*100.0); -Print (bt->right,n); A     } +}

7-24 Tree species statistics (25 points) (Application of binary sorting)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.