poj 2503
来源:互联网 发布:网络攻防技术操作实例 编辑:程序博客网 时间:2024/05/10 05:49
字典树模板题目
#include<stdio.h>#include<string.h>#include<stdlib.h>struct tree{struct tree *son[26];int count;char str[20];}*root;void insert(char *p,char s[]){int i,k,j;tree *cur=root,*next; int len=strlen(p);for(i=0;i<len;i++){k=p[i]-'a';if(cur->son[k]!=NULL)cur=cur->son[p[i]-'a'];else {next=new(tree);for(j=0;j<26;j++)next->son[j]=NULL;next->count=0;cur->son[p[i]-'a']=next;cur=next;}}cur->count=1;strcpy(cur->str,s);}int find(char *p){int i;tree *cur=root;int len=strlen(p);for(i=0;i<len;i++){int k=p[i]-'a';if(cur->son[k]==NULL)break;else cur=cur->son[k];}if(i<len||cur->count==0)return 0;else printf("%s\n",cur->str);}int main(){int i,j,k;char s1[20],s2[20],s[100];root=new(tree); for(i=0;i<26;i++)root->son[i]=NULL;root->count=0;while(gets(s),s[0]){j=0;for(i=0;s[i]!=' ';i++)s1[j++]=s[i];s1[j]='\0';j=0;for(i=i+1;s[i];i++)s2[j++]=s[i];s2[j]='\0';insert(s2,s1);}while(scanf("%s",s)!=-1){j=find(s);if(j==0)printf("eh\n");}return 0;}
- Poj 2503
- poj 2503
- POJ 2503
- POJ 2503
- poj 2503
- poj 2503
- POJ 2503
- poj-2503
- poj 2503
- poj- 2503
- poj 2503
- POJ 2503
- POJ-----2503
- poj 2503 Babelfish
- POJ 2503 Babelfish(HASH)
- POJ 2503 //map
- poj 2503 Babelfish
- POJ 2503 Babelfish
- 20130507 printf("%*.*f",fieldWidth,precision,fval);
- 使用Google语音识别引擎(Google Speech API)[3月5日修改]
- 面试亚信,参杂感悟,其实全是废话连篇
- android中webview接收favicon总是获取为null解决方案
- 业界资讯:flash cc 诞生
- poj 2503
- 子集和问题
- win7 下Qt creator + Qt library + MinGw的安装和配置
- c++内存泄漏检测
- /etc/ld.so.conf文件 作用 -2013-05-07
- Android启动画面实现
- 试除法质数打表方法的逐步改进--经典面试题
- 【C/C++】ASCII字符集
- itext 输出多页PDF