HDU 1075 What Are You Talking About
来源:互联网 发布:做优化代理 编辑:程序博客网 时间:2024/05/19 20:46
题意:给出一些火星文及对应的英文翻译,然后给出一些火星文句子,把它翻译成英文。
分析:字典树。对火星单词建立字典树,在单词末尾记录对应的英文。
Code:
#include <algorithm>#include <iostream>#include <cstring>#include <string>#include <cstdio>#include <vector>#include <queue>#include <cmath>#include <map>#include <set>#define eps 1e-7#define LL long long#define pb push_back#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define Max(a,b) ((a)>(b)?(a):(b))#define Min(a,b) ((a)<(b)?(a):(b))using namespace std;struct Trie{ bool End; char s[11]; Trie *Next[26];}root;char str[3005],word[11];void InsertTrie(int len){ Trie *p=&root; for(int i=0;i<len;i++){ int id=str[i]-'a'; if(p->Next[id]==NULL){ Trie *q=new Trie; for(int i=0;i<26;i++) q->Next[i]=NULL; q->End=false; p->Next[id]=q; p=p->Next[id]; } else p=p->Next[id]; } p->End=true; strcpy(p->s,word);}bool Search(int len){ Trie *p=&root; for(int i=0;i<len;i++){ int id=str[i]-'a'; p=p->Next[id]; if(p==NULL) return false; } if(p->End) { printf("%s",p->s); return true; } return false;}int main(){ scanf("%s",str); for(int i=0;i<26;i++) root.Next[i]=NULL; while(scanf("%s",word),strcmp(word,"END")){ scanf("%s",str); InsertTrie(strlen(str)); } scanf("%s",word);getchar(); char c; int all=0; while(c=getchar()){//这种输入方式很好处理 if((c<'a'||c>'z')&&(c<'A'||c>'Z')){ str[all]='\0'; if(!strcmp(str,"END")) break; if(!Search(strlen(str))) printf("%s",str); putchar(c); all=0; } else str[all++]=c; } 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
- Android获取其他包的Context实例然后干坏事
- Linux内核对三层协议的管理
- hibernate的getSession和getCurrentSession源码解析
- 磁盘管理——LVM
- 日语动词变形总结
- HDU 1075 What Are You Talking About
- hdu 2825 Wireless Password(AC自动机+压缩DP,5级)
- 多线程--基础篇2--同步
- 天乐文本文件按行分割器_v1.0正式版【专业制作&极速分割】
- Windows环境下搭建Qt开发环境
- win8中 用office 提示值不在预期的范围内
- Combinations
- 位操作-找到数组中只出现一次的数字
- 为你的记事本增加扩展新的功能