POJ2418 Hardwood Species
作者:互联网
POJ2418
筱柒Littleseven
QQ:3534947775
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define MAXN 300030
using namespace std;
#define long long LL
#define eps 1e-8
int tot=0,sum; char ss[110],s[110];
struct Trie{ int nex[256]; double num;}trie[MAXN];
void insert(char s[])
{
int now=0,len=strlen(s+1);
for(int i=1;i<=len;i++)
{
int ch=s[i];
if(!trie[now].nex[ch]) trie[now].nex[ch]=++tot;
now=trie[now].nex[ch];
}
trie[now].num++;
}
void print(int p,int len)
{
if(trie[p].num>=eps) printf("%s %.4lf\n",ss,trie[p].num*100/sum);
for(int i=1;i<=256;i++)
{
if(trie[p].nex[i]!=0)
{
ss[len]=i; print(trie[p].nex[i],len+1); ss[len]='\0';
}
}
}
int main()
{
while(gets(s+1))
{
insert(s); sum++;
}
print(0,0);
return 0;
}
标签:Hardwood,char,int,num,POJ2418,include,Species,define 来源: https://blog.csdn.net/qq_43473791/article/details/94402471