请修改,不用输入这么多相同树目,一次就可输入大量数目

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct tree
{
char data[25];
int num;
struct tree *lc, *rc;
} BiTree;
double x;
BiTree *Creat(BiTree *T, char s)
{
if(T == NULL)
{
T = (BiTree
)malloc(sizeof(BiTree));
T->lc = NULL;
T->rc = NULL;
T->num = 1;
strcpy(T->data, s);
}
else
{
int k = strcmp(T->data, s);
if(k == 0)
T->num++;
else if(k > 0)
T->lc = Creat(T->lc, s);
else
T->rc = Creat(T->rc, s);
}
return T;
}

void Mid(BiTree *T) //中序遍历输出树名和百分比
{
if(T)
{
Mid(T->lc);
printf("%s %.2lf%%\n", T->data, (T->num/x)*100);
Mid(T->rc);
}
}

int main()
{
int n, i;
char s[25];
BiTree *T;
T = NULL;
scanf("%d", &n);
x = n; //全局变量double x保存n的值
getchar(); /™掉回车键
while(n--)
{
gets(s);
for(i = 0; s[i] != '\0'; i++)
{
if(s[i] <= 'Z' && s[i] >= 'A') //将所有大写转换成小写
s[i] = s[i] + 32;
}
T = Creat(T, s);
}
Mid(T);
return 0;
}

img

用scanf("%s",s);
这样每个节点都用空格分开