HDU 1075 What Are You Talking About(字典树)
来源:互联网 发布:淘宝网最热销的产品 编辑:程序博客网 时间:2024/04/30 14:18
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1075
还是赤裸裸的字典树问题。还是几乎套模版来做。。。。。。除了复制标记以外的跟上一篇博客统计难题没什么区别。不过一个小细节还是坑了一个小时。。。。。直接上代码。。。。。
#include<stdio.h>#include<string.h>#include<stdlib.h>struct node { bool flag;/*标记是否后面有连接字符串*/ char ch[26];/*保存连接的字符串*/ struct node *next[26];};struct node *root;struct node *newset()/*新建结点功能*/{ struct node *p=(struct node *)malloc(sizeof(struct node)); p->ch[0]=0;/*头结点置空,不放任何字母*/ p->flag=false; for(int i=0;i<26;i++) { p->next[i]=NULL; } return p;}void insert(char *s,char *res)/*建立字典树功能*/{ struct node *p; p=root; int len=strlen(s); for(int i=0;i<len;i++) { if(p->next[s[i]-'a']==NULL) { p->next[s[i]-'a']=newset(); p=p->next[s[i]-'a']; } else { p=p->next[s[i]-'a']; } } strcpy(p->ch,res); p->flag=true;}char *find(char *s)/*查找功能*/{ struct node *p; p=root; int len=strlen(s); for(int i=0;i<len;i++) { if(p->next[s[i]-'a']==NULL) { return s; } else { p=p->next[s[i]-'a']; } } if(p->flag==true) return p->ch;/*如果找得到,翻译*/ else return s;/*否则不翻译*/}int main(){ int i,k,len; char a[10001],b[10001],str[10001]; scanf("%s",a);/*相当于START*/ root=newset(); while(scanf("%s",a)) { if(strcmp(a, "END")==0) break; scanf("%s",b); insert(b,a);/*建立字典树*/ } memset(b,0,sizeof(b));/*坑......*/ scanf("%s",a);/*相当于START*/ getchar();/*吸收回车*/ while(1) { gets(str); if(strcmp(str,"END")==0) break; len=strlen(str); for(k=0,i=0;i<len;i++) { if(str[i]>='a'&&str[i]<='z') { b[k++]=str[i]; } else { k=0; printf("%s",find(b)); if(i<len) { printf("%c",str[i]); } memset(b,0,sizeof(b));/*清空*/ } } printf("\n"); } return 0;}
- HDU 1075 What Are You Talking About(字典树)
- hdu-1075-What Are You Talking About-(字典树)
- hdu 1075 What Are You Talking About(字典树)
- HDU 1075 What Are You Talking About(字典树)
- hdu 1075 What Are You Talking About(字典树)
- HDU - 1075 - What Are You Talking About(字典树)
- HDU 1075 What Are You Talking About (字典树)
- HDU 1075 What Are You Talking About(字典树)
- HDU 1075 What Are You Talking About(字典树)
- hdu 1075 What Are You Talking About (字典树)
- hdu 1075 What Are You Talking About(字典树方法)
- hdu 1075 What Are You Talking About 字典树
- HDU 1075 What Are You Talking About 字典树
- hdu 1075 What Are You Talking About(字典树)
- hdu 1075 What Are You Talking About (字典树)
- hdu 1075 What Are You Talking About 字典树
- hdu 1075 What Are You Talking About(字典树)
- [字典树] HDU 1075 - What Are You Talking About
- 关于Latent Dirichlet Allocation及Hierarchical LDA模型的必读文章和相关代码
- 活在当下
- beanUtils webUtils UUID使用
- C# 使用Excel模板复制单元格
- Cookie&Session理解与应用
- HDU 1075 What Are You Talking About(字典树)
- 曾获资4100万美元的Color现日活跃用户仅为区区3万
- 优秀是一种习惯(转)
- 色环电阻识别方法
- 解决poi导出excel中文列宽问题
- 让win7 支持调试
- 高中生也能成为软件达人吗?
- 问题,大大的,!
- 解决win2003远程超出最大连接数故障的方法