Language of FatMouse


Time Limit: 10 Seconds     
Memory Limit: 32768 KB


We all know that FatMouse doesn't speak English. But now he has to beprepared since our nation will join WTO soon. Thanks to Turing we havecomputers to help him.

Input Specification

Input consists of up to 100,005 dictionary entries, followed by a blankline, followed by a message of up to 100,005 words. Each dictionaryentry is a line containing an English word, followed by a space and a FatMouse word.No FatMouse word appears more than
once in thedictionary. 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 10lowercase 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 ogday
cat atcay
pig igpay
froot ootfray
loops oopslay atcay
ittenkay
oopslay

Output for Sample Input

cat
eh loops 题解:建科字典树,单词插入的结尾记录该单词相应的单词的下标,查询就可以。
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cstdlib> #define N 100020 using namespace std; char s[12];
char ans[N][12]; struct Trie {
int id;
struct Trie *nxt[26];
Trie() {
id=0;
for(int i=0; i<26; i++) {
nxt[i]=NULL;
}
}
}; void Trie_Inser(Trie *p,char s[],int id) {
int i=0;
Trie *q=p;
while(s[i]) {
int nx=s[i]-'a';
if(q->nxt[nx]==NULL) {
q->nxt[nx]=new Trie;
}
i++;
q=q->nxt[nx];
}
q->id=id;
} int Trie_Serch(Trie *p,char s[]) {
Trie *q=p;
int i=0;
while(s[i]) {
int nx=s[i]-'a';
if(q->nxt[nx]==NULL)return 0;
q=q->nxt[nx];
i++;
}
return q->id;
} int main() {
//freopen("test.in","r",stdin);
Trie *p=new Trie;
int id=1;
char a[40];
while(1) {
gets(a);
if(a[0]=='\0')break;
int l=0;
int len=strlen(a);
int i;
for(i=0; i<len; i++) {
if(a[i]==' ')break;
ans[id][l++]=a[i];
}
ans[id][l]='\0';
l=0;
i++;
for(; i<len; i++) {
s[l++]=a[i];
}
s[l]='\0';
//printf("%s %s\n",ans[id],s);
Trie_Inser(p,s,id);
id++;
}
while(~scanf("%s",s)) {
id=Trie_Serch(p,s);
if(id==0) {
printf("eh\n");
} else {
printf("%s\n",ans[id]);
}
}
return 0;
}

zoj 1109 Language of FatMouse(字典树)的更多相关文章

  1. zoj 1109 zoj 1109 Language of FatMouse(字典树)

    好开心,手动自己按照字典树的思想用c写了一个优化后的trie字典树,就是用链表来代替26个大小的字符数组.完全按照自己按照自己的想法打的,没有参考如何被人的代码.调试了一天,居然最后错在一个小问题上, ...

  2. zoj 1109 Language of FatMouse(map映照容器的典型应用)

    题目连接: acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1109 题目描述: We all know that FatMouse doe ...

  3. ZOJ 1109 Language of FatMouse

    较简单字典树,每输入一对字符串,前一个放在字典(数组)中,后一个插入字典树中,并将其最终的flag赋为前一个在数组中的下标,再就好找了.输入的处理方法要注意一下. 代码: #include <i ...

  4. zoj 1109 Language of FatMouse(map)

    Language of FatMouse Time Limit: 10 Seconds      Memory Limit: 32768 KB We all know that FatMouse do ...

  5. ZOJ 1109 Language of FatMouse 【Trie树】

    <题目链接> 题目大意: 刚开始每行输入两个单词,第二个单词存入单词库,并且每行第二个单词映射着对应的第一个单词.然后每行输入一个单词,如果单词库中有相同的单词,则输出它对应的那个单词,否 ...

  6. zoj 1109 Language of FatMouse 解题报告

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=109 题目意思:给出一个mouse-english词典,问对于输入的m ...

  7. ZOJ Problem Set - 1109 Language of FatMouse

    这道题目最让人头疼的就是该题的input怎么结束,因为它要求输入一个空行的时候则一串字符串输入结束,这就不得不让人绕个弯来解决这个问题. (注:本人习惯于使用C中的字符串操作,但是用到map要求使用s ...

  8. zoj1109-Language of FatMouse 【字典树】

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=109 Language of FatMouse Time Limit: 10 S ...

  9. ZOJ 3674 Search in the Wiki(字典树 + map + vector)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4917 题意:每一个单词都一些tips单词. 先输入n个单词和他们的t ...

随机推荐

  1. linux加固目标和对象

    一.  linux加固目标和对象 项目加固的目标:  解决今年信通公司在风险评估工作中发现的linux服务器存在的安全问题,并结合南方电网安全基线标准修订版部署相关要求,将linux服务器的安全状况提 ...

  2. unity shader 编译时间过长

    去掉opengles2.0能省一半时间 换ssd  Compiled shader 'Shader Forge/Scenes_Ground_Standard_M' in 315.51s    gles ...

  3. Mount CIFS

    mount -t cifs -o username="共享用户",password="密码" //ip/sharing_folder /mountpoint [ ...

  4. [Angular] Two things about OnChanges Lifecycle hook

    1. ngOnChanges is called before ngOnInit but after constructor() 2. ngOnChanges is called because of ...

  5. sonatype Nexus3 install on Kubernetes

    Nexus 搭建代码 apiVersion: extensions/v1beta1 kind: Deployment metadata: name: nexus3 labels: app: nexus ...

  6. js 终止 for 循环

    1.break语句会使运行的程序立刻退出包含在最内层的循环或者退出一个switch语句. 2.for循环如果是多层循环 可以将循环命名,跳出指定的循环. first://需要将循环命名 for(var ...

  7. ES6 Promise catch

    getJSON方法返回一个 Promise 对象,如果该对象状态变为resolved,则会调用then方法指定的回调函数:如果异步操作抛出错误,状态就会变为rejected,就会调用catch方法指定 ...

  8. 使用python进行图像处理-调整图片大小

    python有一个图像处理库——PIL,可以处理图像文件.PIL提供了功能丰富的方法,比如格式转换.旋转.裁剪.改变尺寸.像素处理.图片合并等等等等,非常强大. 举个简单的例子,调整图片的大小: im ...

  9. 【SSH进阶之路】Struts基本原理 + 实现简单登录(二)

    上面博文,主要简单的介绍了一下SSH的基本概念,比較宏观,作为刚開始学习的人可以有一个总体上的认识,个人觉得对学习有非常好的辅助功能.它不不过一个"瞭望塔".更是检验是否真正掌握全 ...

  10. Repository与UnitOfWork引入

    Repository是什么? 马丁大叔的书上同样也有解释:它是衔接数据映射层和域之间的一个纽带,作用相当于一个在内存中的域对象映射集合,它分离了领域对象和数据库访问代码的细 节.Repository受 ...