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)