题目是不难,但是输入有点难,可能碰到的情况还是少了点
#include<cstdio>
#include<iostream>
#include<cstring>
#include<sstream>
using namespace std;
const int maxn=2e6+5;
int tree[maxn][30];
bool flagg[maxn];
int tot;
string s,st;
int cnt;
int flag;
void insert_(string str)
{
int len=str.length();
int root=0;
for(int i=0;i<len;i++)
{
int id=str[i]-'a';
if(!tree[root][id]) tree[root][id]=++tot;
root=tree[root][id];
}
if(!flagg[root]){
flagg[root]=true;
cnt++;
}
}
void init()//×îºóÇå¿Õ£¬½Úʡʱ¼ä
{
for(int i=0;i<=tot;i++)
{
flagg[i]=false;
for(int j=0;j<10;j++)
tree[i][j]=0;
}
tot=0;cnt=0;
}
int main()
{
while(getline(cin,s)){
if(s[0]=='#')
break;
init();
stringstream ss(s);
while(ss>>st)
insert_(st);
printf("%d\n",cnt);
}
return 0;
}