#include<bits/stdc++.h>
using namespace std;
typedef struct no
{
char data[25];
int num;
struct no *lc,*rc;
}node;
int n;
node *creat(char *n)
{
node *p;
p=new node;
p->num=1;
strcpy(p->data,n);
p->lc=NULL;
p->rc=NULL;
return p;
}
void bulid(node *&root,char *n)
{
if(!root)
{
root=creat(n);
}
else
{
int cmp=strcmp(root->data,n);
if(cmp>0)
bulid(root->lc,n);
else if(cmp<0)
bulid(root->rc,n);
else
root->num++;
}
}
void middle(node *root)
{
if(root)
{
middle(root->lc);
printf("%s %.2lf%c\n",root->data,root->num*100.00/n,'%');
middle(root->rc);
}
}
int main()
{
scanf("%d\n",&n);
node *p;
char b[25];
p=NULL;
for(int i=0;i<n;i++)
{
gets(b);
for(int j=0;b[j];j++)
{
if(b[j]>='A'&&b[j]<='Z')
b[j]+=32;
}
bulid(p,b);
}
middle(p);
return 0;
}
数据结构实验之查找三:树的种类统计
最新推荐文章于 2022-03-24 15:26:51 发布