you are my friend #
4
#include<stdio.h> #include<string.h> char a[110]; char s[100]; int ch[10010][26]; int val[10010] ,sz ,ans; int id(char c) { return c-'a'; } void Inse(char *s , int n ) { int u=0 ; for(int i=0;i<n;i++) { int c=id(s[i]); if(!ch[u][c]) { ch[u][c]=sz++; } u=ch[u][c]; } if(val[u] == 0) ans++; val[u]=1; } int main() { while(1) { gets(a); if(a[0] == '#') break; int len=strlen(a); a[len]=' '; a[len+1]=0; memset(ch,0,sizeof(ch)); memset(val,0,sizeof(val)); sz=1 ,ans=0; int k=0; for(int i=0;a[i];i++) { if(a[i] != ' ' ) { s[k++]=a[i]; } else if(s[0] != 0){ // printf("%s",s); Inse(s , k); memset(s,0,sizeof(s)); k=0; } } printf("%d\n",ans); } return 0; }
原文:http://blog.csdn.net/u013923947/article/details/29194379