diff --git a/HDOJ/1251.cpp b/HDOJ/1251.cpp new file mode 100644 index 0000000..fa7465b --- /dev/null +++ b/HDOJ/1251.cpp @@ -0,0 +1,55 @@ +/// HDU 1251 +#include +#include +#include +using namespace std; + +struct node +{ + node* next[26]; + int val; + node(){val=0;memset(next,0,sizeof(next));} +}; +char buffer[1024]; +node _root; +node* root=&_root; +int main() +{ + while(gets(buffer)) + { + if(strlen(buffer)<1) + { + break; + } + char* p=buffer; + node* np=root; + while(*p!=0) + { + if(np->next[*p-'a']==NULL) np->next[*p-'a']=new node; + np=np->next[*p-'a']; + p++; + np->val++; + } + } + while(gets(buffer)) + { + char* p=buffer; + node* np=root; + bool undone=true; + while(*p!=0) + { + if(np->next[*p-'a']==NULL) + { + printf("0\n");undone=false;break; + } + np=np->next[*p-'a']; + p++; + } + if(undone) + { + printf("%d\n",np->val); + } + } + return 0; +} +