rt,题目不在本站,附个链接:题目地址
能帮倒忙的话就太感谢了
#include<bits/stdc++.h>
#define EndFlag NULL
using namespace std;
typedef string ElemType;
typedef struct BSTNode{
ElemType data;
int num;
BSTNode* lchild,*rchild;
BSTNode(){
num=0;
}
}BSTNode,*BSTree;
int tot=0;
void InsertBST(BSTree& T,ElemType e){
if(!T){
BSTree S = new BSTNode;
S->data = e;
S->lchild = S->rchild = NULL;
T = S;
T->num++;
}else if(e < T->data){
InsertBST(T->lchild,e);
}else if(e > T->data){
InsertBST(T->rchild,e);
}else if(e == T->data){
T->num++;
}
}
void CreateBST(BSTree& T){
T = NULL;
ElemType e;
while(getline(cin,e)){
InsertBST(T,e);
tot++;
}
}
void inorder(BSTree& T){
if(T){
inorder(T->lchild);
cout<<T->data;
printf(" %0.4lf\n",(T->num*100.0) / (tot*1.0));
inorder(T->rchild);
}
}
int main(){
freopen("in.in","r",stdin);
freopen("out.out","w",stdout);
BSTree T;
CreateBST(T);
inorder(T);
return 0;
}
``