Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 一直以为我的BST写的很挫，看了讨论，觉得还行。。1100ms

Posted by proverbs at 2012-08-14 21:50:51 on Problem 2418 and last updated at 2012-08-14 21:52:20
```#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
struct TREE
{
int l,r,cs;bool fg;char str[40];
}T[2000010];
int cnt=1,num=1;
char tree[40];
void copy(int u)
{
int len=strlen(tree);
for(int i=0;i<len;i++) T[u].str[i]=tree[i];
}
void insert(int u)
{
if(!T[u].fg)
{
copy(u);
T[u].l=++cnt; T[u].r=++cnt; T[u].cs=1; T[u].fg=true;
}
else
{
int cp=strcmp(tree,T[u].str);
if(cp<0) insert(T[u].l);
else if(cp>0) insert(T[u].r);
else T[u].cs++;
}
}
{
gets(tree);
copy(1); T[1].fg=true; T[1].l=++cnt; T[1].r=++cnt; T[1].cs=1;
while(gets(tree))
{
insert(1);
num++;
}
}
void prt(int u)
{
if(T[u].fg==0) return;
prt(T[u].l);
printf("%s %.4lf\n",T[u].str,double(T[u].cs)/double(num)*100.0);
prt(T[u].r);
}
int main()
{
prt(1);
//system("pause");
return 0;
}
```

Followed by: