ZOJ1109 Language of FatMouse
来源:互联网 发布:c语言求四个数平均值 编辑:程序博客网 时间:2024/05/18 01:48
题目链接:ZOJ1109
We all know that FatMouse doesn't speak English. But now he has to be prepared since our nation will join WTO soon. Thanks to Turing we have computers to help him.
Input Specification
Input consists of up to 100,005 dictionary entries, followed by a blank line, followed by a message of up to 100,005 words. Each dictionary entry is a line containing an English word, followed by a space and a FatMouse word. No FatMouse word appears more than once in the dictionary. The message is a sequence of words in the language of FatMouse, one word on each line. Each word in the input is a sequence of at most 10 lowercase letters.
Output Specification
Output is the message translated to English, one word per line. FatMouse words not in the dictionary should be translated as "eh".
Sample Input
dog ogdaycat atcaypig igpayfroot ootfrayloops oopslayatcayittenkayoopslay
Output for Sample Input
catehloops
题目分析:跟之前HDU1075火星文的题几本一样,我们只需要标记好串尾就行了。
//// main.cpp// ZOJ1109//// Created by teddywang on 16/4/1.// Copyright © 2016年 teddywang. All rights reserved.//#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;typedef struct node { int num; node *next[26];}trienode;trienode *root;char s[100040][13];int l;void insert_node(char *t,int num){ int len=strlen(t); trienode *h,*r=root; for(int i=0;i<len;i++) { int buf=t[i]-'a'; if(r->next[buf]==NULL) { h=new node; h->num=-1; for(int j=0;j<26;j++) h->next[j]=NULL; r->next[buf]=h; r=h; } else r=r->next[buf]; } r->num=num;}int find(char *t){ int len=strlen(t); trienode *r=root; for(int i=0;i<len;i++) { int buf=t[i]-'a'; if(r->next[buf]==NULL) return -1; else r=r->next[buf]; } return r->num;}void del(trienode *r){ for(int i=0;i<26;i++) { if(r->next[i]!=NULL) del(r->next[i]); } free(r);}int main(){ root=new node; root->num=-1; for(int i=0;i<26;i++) root->next[i]=NULL; l=0; char t[30]; while(gets(t)&&t[0]!='\0') { int i=0; for(i=0;t[i]!=' ';i++) { s[l][i]=t[i]; } insert_node(t+i+1,l); l++; memset(t,0,sizeof(t)); } while(~scanf("%s",t)) { int pos=find(t); if(pos==-1) printf("eh\n"); else printf("%s\n",s[pos]); } del(root);}
- ZOJ1109 Language of FatMouse
- ZOJ1109 Language of FatMouse
- ZOJ1109 Language of FatMouse,BST
- zoj1109-Language of FatMouse 字典树
- zoj1109 水题(大神绕道) Language of FatMouse
- Language of FatMouse
- C - Language of FatMouse
- zoj_1109 Language of FatMouse
- ZOJ 1109 Language of FatMouse
- zoj 1109 Language of FatMouse
- ZOJ 1109Language of FatMouse
- zoj 1109.Language of FatMouse
- ZOJ 1109 Language of FatMouse
- ZOJ 1109 Language of FatMouse
- ZOJ 1109 Language of FatMouse
- zoj 1109 Language of FatMouse
- ZOJ-1109 -Language of FatMouse
- zoj 1109 Language of FatMouse
- 朴素贝叶斯(naive bayes)
- 初入linux世界
- Visual Studio 2010下的OpenCV 2.4.10安装过程
- Ubuntu12.04 编译 Hadoop 2.6.4 源码
- DrawableWrapper
- ZOJ1109 Language of FatMouse
- C++中虚析构函数的作用
- Tcl -- lappend
- java.io.IOException: Cannot find any registered HttpDestinationFactory from the Bus.
- Android 插件化框架 DynamicLoadApk 源码解析
- Spring 拦截器配置
- C++实验2-学生成绩
- Java经典设计模式(1):五大创建型模式(附实例和详解)
- 使用本地JConsole监控远程JVM