hdu 1075 What Are You Talking About(字典树方法)
来源:互联网 发布:存储过程执行sql语句 编辑:程序博客网 时间:2024/04/29 10:03
本来就是字典树的题目。。所以就又用字典树敲了一遍 一A 还算顺利
大题结构像刚才那个一样 主要是超找一个 单词
首先预处理的时候 insert 火星文 然后用字典树 记录index 最后用vector 记录 翻译过来的英文 index一样。
就差不多就这样了。。
顺便说一下 刚才水的map1300+ms
tire 树300+ms
#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<vector>using namespace std;struct Node{ int index; Node * child[26]; Node(){ index=-1; for(int i=0;i<26;++i) child[i]=NULL; }};Node *root, *p;char str1[15],str2[15],str[3005];vector<string> vec;int index;void insert(char str[]){ p=root; int i,j,len=strlen(str); for(i=0;i<len;++i) { if(p->child[str[i]-'a']==NULL) { p->child[str[i]-'a']=new Node(); } p=p->child[str[i]-'a']; } p->index=index;}int Find(char str[]){ int i,len=strlen(str); p=root; for(i=0;i<len;++i) { if(p->child[str[i]-'a']==NULL) return -1; p=p->child[str[i]-'a']; } return p->index;}int main(){ int i,j; index=0; gets(str1); root = new Node(); while(scanf("%s",str1)) { if(strcmp(str1,"END")==0) break; scanf("%s",str2); insert(str2); vec.push_back(string(str1)); index++; } getchar(); gets(str); while(gets(str)) { if(strcmp(str,"END")==0) break; for(i=0;str[i];++i) { if(str[i]<'a' || str[i]>'z') { printf("%c",str[i]); continue; } for(j=0; str[i]>='a' && str[i]<='z' ;++i,++j) str1[j]=str[i]; i--; str1[j]='\0'; int t=Find(str1); if(t>=0) cout<<vec[t]; else printf("%s",str1); } puts(""); } 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 字典树 trie
- 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
- Linux使用命令大杂烩
- 项目2辅助学习练习五
- 如何在python中读写和存储matlab的数据文件(*.mat)
- Linux芯片级移植与底层驱动(基于3.7.4内核)
- 黑马程序员__JAVA高新技术--枚举及内省JavaBean、可变参数等知识点总结
- hdu 1075 What Are You Talking About(字典树方法)
- mysql的alter用法总结
- Maven使用
- Dtor
- 学习指针-指针终极理解
- Java静态方法,静态变量,初始化顺序
- 指针使用的注意事项
- oracle 安装 登录
- java语言学习