字典树,ZOJ 1109 不得不说~

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


Time Limit: 10 Seconds      Memory Limit: 32768 KB


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 ogday
cat atcay
pig igpay
froot ootfray
loops oopslay

atcay
ittenkay
oopslay

Output for Sample Input

cat
eh
loops

Source: Zhejiang University Training Contest 2001

解题总结:这一题给的时间挺长的,10S,用C++里的模板map就可以通过了,好像也不超过两秒的样子,但是作为字典树的练

习,还是以字典树做了,第一次写字典树,没有参考别人的用法,就自个儿琢磨了个递归生成与遍历~实现:用结构题存储其英文

翻译及当前字符所能对应的next 指针,生成树时,对当前对应字符的指针进行判断,不存在则增加,存在直接进入递归直至新增

添的单词至末尾。查找时用同样的思路~、、、

出现的问题:结构体设置不合理,导致超出内存;内存申请时运用错误(node=(Tree)malloc(sizeof(Node)/*Tree*/)),花

了好久跟踪还能找出错误,,,末尾字符判断不精确,WA~

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值