hdu 1075 字典树
来源:互联网 发布:康有为和孙中山 知乎 编辑:程序博客网 时间:2024/05/18 21:11
int 定义为char,re了2个小时,人才啊。。。。。。。。。。。。
注意点,abc 对应efg,输入efg应该输出abc,输入ef呢?
注意输入前缀无输出的情况
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<cstring>#include"ctype.h" struct Dictree{int no;struct Dictree *next[26];}*root;char str[500005][15],s[3005],p[2005];void create_tree();void insert(char *,int );int find(char *);int main(){int i=0,j=0,k=0,temp,len;create_tree();scanf("%s",s);while(scanf("%s",str[i]),strcmp(str[i],"END")!=0){scanf("%s",p); insert(p,i++);}scanf("%s",s),getchar();while(gets(s)){if(strcmp(s,"END")==0)break;len=strlen(s);k=0;for(j=0;j<len;j++){if(islower(s[j])) p[k++]=s[j];else{if(k){p[k]=0;temp=find(p);if(temp==-1) printf("%s",p);else printf("%s",str[temp]);}if(s[j]) printf("%c",s[j]);k=0;}}memset(s,0,sizeof(s));putchar('\n'); }return 0;}void insert(char *s,int k){int i,j;struct Dictree *p,*t;p=root;for(i=0;s[i];i++){if(p->next[s[i]-'a']==NULL){t=(struct Dictree*)malloc(sizeof(struct Dictree));t->no=-1;for(j=0;j<26;j++)t->next[j]=NULL;p->next[s[i]-'a']=t;}p=p->next[s[i]-'a'];}p->no=k;}int find(char *s){int i;struct Dictree *p=root;for(i=0;s[i];i++){if(p->next[s[i]-'a']==NULL)return -1;else p=p->next[s[i]-'a'];}return p->no;}void create_tree(){int i;root=(struct Dictree*)malloc(sizeof(struct Dictree));root->no=-1;for(i=0;i<26;i++) root->next[i]=NULL;}
- [字典树]hdu 1075
- hdu 1075 字典树
- 字典树 hdu 1075
- hdu 1075 字典树
- HDU 1075 字典树
- hdu 1075 字典树
- hdu 1075 字典树
- 字典树 hdu 1075
- hdu 1075 字典树
- hdu 1075 字典树
- HDU 1075 字典树
- 字典树 hdu 1075
- hdu 1075 字典树
- HDU 1075 字典树
- hdu 1075 字典树
- HDU 1075 字典树裸
- HDU-1075(字典树入门)
- hdu 1075 (字典树)
- Vijos 1243 生产产品[单调队列优化dp]
- googleEye 的简单实现
- php实现验证码的识别(中级篇)
- Android的View, SurfaceView学习
- HDU 4377 Sub Sequence[串构造]
- hdu 1075 字典树
- C#开发wince应用程序
- 如何将“结果越差评分越高”的值转换为“结果越好评分越高”的值?
- 一个陌生女人的来信——茨威格
- ASIHTTPRequest系列(一):同步和异步请求
- Nmap源码分析(端口扫描)
- ASIHTTPRequest系列(二):文件下载
- to support Chinese in Win7 English version
- ASIHTTPRequest系列(三):文件上传