POJ_2503_Babelfish_(Trie/map)
2016-05-13 17:48
260 查看
描述
http://poj.org/problem?id=2503
给出一个字典,求翻译,翻译不了输出eh.
Babelfish
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 39335 | Accepted: 16797 |
Description
You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have a dictionary to help you understand them.
Input
Input consists of up to 100,000 dictionary entries, followed by a blank line, followed by a message of up to 100,000 words. Each dictionary entry is a line containing an English word, followed by a space and a foreign language word. No foreign word appears more than once in the dictionary. The message is a sequence of words in the foreign language, one word on each line. Each word in the input is a sequence of at most 10 lowercase letters.
Output
Output is the message translated to English, one word per line. Foreign 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
Sample Output
cat eh loops
Hint
Huge input and output,scanf and printf are recommended.
Source
Waterloo local 2001.09.22
分析
网上看到map可直接做,但我就是想打打Trie模板...
p.s.据说哈希也能做,但我完全不知道那是啥...
Trie做法:在每个单词节点存下对应翻译的字符串.
Trie:
#include <iostream> #include <cstdio> #include <string> #include <map> using namespace std; char c[25],a[15],b[15]; map <string,string> m; int main(){ while(cin.getline(c,25)){ if(c[0]=='\0') break; sscanf(c,"%s %s",a,b); m[b]=a; } map <string,string> :: iterator it; while(cin.getline(c,25)){ if(c[0]=='\0') break; it=m.find(c); if(it!=m.end()){ printf("%s\n",it->second.c_str()); } else{ printf("eh\n"); } } return 0; } mapView Code
相关文章推荐
- 大凯哥说大数据(系列一):没有云计算就没有大数据
- poj 1159 Palindrome
- python 3D绘制立体几何
- Spring事务中涉及到多线程的处理方式
- SVN使用教程1
- magento 的一些Sql查询
- 作业_java基础第七天_匿名内部类、异常、包和jar
- 基于maven的springmvc+mybatis的web页面的CRUD
- 一篇非常好的讲解转场动画的文章链接
- android获取网络图片
- websocket是什么?
- POJ 3468 A Simple Problem with Integers 线段树 区间修改
- Haar特征
- VC中L""和_T("")的区别
- 为speedphp最新版添加 仿Yii 的简易版 数据验证 支持不同场景,自定义回调
- 静态库与动态库的创建与使用
- 258. Add Digits
- 1》找到接口-浏览器-收集接口
- Swift UITableView 的简单使用
- 设计模式(Design Patterns)