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. 安装pip源

    国内源地址: 豆瓣(douban) http://pypi.douban.com/simple/ 阿里云 http://mirrors.aliyun.com/pypi/simple/ 中国科技大学 h ...

  2. MongoDB分片集群常用操作

    下架主节点: db.adminCommand({replSetStepDown : 1, force : true}) 删除节点: rs.remove("IP:PORT") 新增节 ...

  3. mac 下安装 plink

    1.  直接 brew install putty. 其自带 plink工具.

  4. WPF使用ARCGIS App文件配置Cs后台文件

    using System; using System.Collections.Generic; using System.Configuration; using System.Data; using ...

  5. C# SQLite 创建数据库的方法增删查改语法和命令

    SQLite介绍 SQLite是一个开源.免费的小型RDBMS(关系型数据库),能独立运行.无服务器.零配置.支持事物,用C实现,内存占用较小,支持绝大数的SQL92标准. SQLite数据库官方主页 ...

  6. X 开启新的 X window 服务器

    X -ac -terminate :3 开启服务,禁用访问控制约束,重置时关闭服务,$DISPLAY=:3 此时设置用户程序的 DISPLAY 值,就可在指定的 X 服务器上打开程序,比如 DISPL ...

  7. 手机端UC浏览器,在java开发的下载功能中存在的问题?

    在java web开发中,不同浏览器对下载文件的格式有不同的要求,有时会出现视频,音频等文件无法下载的问题.我在开发中,也遇到类似的问题,觉得很苦恼. 经过百度和请教学习,得到2个解决方案. 首先得到 ...

  8. Linux配置快捷方式路径

    快就一个字,我只说一次! 1.命令顺序: a)       先输入 cd / b)      gedit /etc/profile c)       最后添加路径,看到蓝色部分的没? 把/home更换 ...

  9. Redis源代码解析:13Redis中的事件驱动机制

    Redis中.处理网络IO时,採用的是事件驱动机制.但它没有使用libevent或者libev这种库,而是自己实现了一个很easy明了的事件驱动库ae_event,主要代码只400行左右. 没有选择l ...

  10. Java集合-Map接口相关操作方法

    Map接口不是Collection接口的继承.Map接口用于维护键/值对(key/value pairs). 该接口描述了从不重复的键到值的映射. (1) 添加.删除操作: Object put(Ob ...