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. xss payload

    xss payload可以使用富客户端文本书写,大多数用javascript,少部分用actionscript等等. 1.盗取cookie,发起cookie劫持 使用xss漏洞插入cookie.js ...

  2. unity deferred lighting

    不同于硬件的tbdr 软件层把光照放后面计算也有一个tbdr 先说deferred rendering 再说tiled 1.gbuffer出 G0 albedo ---rgb occlusion -- ...

  3. ISP图像调试工程师——自动白平衡(熟悉3A算法)

    http://blog.csdn.net/wzwxiaozheng/article/details/40586293 https://wenku.baidu.com/view/24632048767f ...

  4. Fragment与Activity传递数据

    MainActivity如下: package cc.testsimplefragment0; import android.os.Bundle; import android.app.Activit ...

  5. xml文件中配置JDBC源遇到问题 : The reference to entity "characterEncoding" must end with the ';' delimiter

    数据源配置时加上编码转换格式后出问题了: The reference to entity"characterEncoding" must end with the ';' deli ...

  6. g++ 静态库连接顺序的巨坑

    在编译最新版本(12.04)的alljoyn的chat示例的时候,想使用bundle daemon,依照在以前的经验修改文件:alljoyn-14.02.00-src/build/linux/x86_ ...

  7. C#中如何动态加载DockPanel

    在WinForm项目中要求实现动态加载DockPanel. 简单研究了下,演示代码如下: 很简单几行代码,实现了基本意图.看起来问题很快解决. 但是实际应用中发现几个问题: 1.当第一次运行时,doc ...

  8. Netty Client和Server端实现

    本文基于Nett4.0.26.Final版本浅析Client与Server端通讯,先看服务器端: public class Server { public static void run(int po ...

  9. C# Meta Programming - Let Your Code Generate Code - 利用反射重写自动的ToString()

    我们在写一些Model的时候,经常会重写ToString,为了在控制台中进行打印或者更好的单元测试. 但是,如果Model的字段非常多的时候,如此简单的重复劳动经常会变成一件令人头痛的事情,因为大家 ...

  10. 饿了么ui添加事件

    最近饿了么ui挺火,连美团都有项目组再用,刚好最近项目重构,就引入了进来,刚用上就发现一个大坑,在配合vue使用时,居然无法添加自定义事件 找了半天才发现原因是需要在事件后面加上  ‘’.native ...