poj_2503(map映射)
2016-04-04 13:43
381 查看
题目链接poj2503
Babelfish
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
Sample Output
Hint
Huge input and output,scanf and printf are recommended.
Source
Waterloo local 2001.09.22
Babelfish
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 38820 | Accepted: 16578 |
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
/*题目大意:给定一系列外国单词,都对应着英语单词。然后给一个外国单词,要求输出相对应的英语单词。若不存在则输出eh 算法分析:可以根据map的映射关系 */ #include <iostream> #include <map> #include <string> #include <cstring> #include <cstdlib> #include <cstdio> using namespace std; int main() { map <string, bool> appear; //记录单词是否出现 map <string , string > p; //单词映射 char t; while (true) { char english[20]; char t; //临时字符 t = getchar(); if (t == '\n') break; //如果是换行符,跳出 int i = 1; english[0] = t; while (true) { t = getchar(); if (t == ' ') { english[i] = '\0'; break; } else english[i++] = t; } string forign; cin >> forign; getchar(); //吃掉换行符 appear[forign] = true; p[forign] = english; } string word; while (cin >> word) { if (appear[word]) cout << p[word] << endl; else cout << "eh" << endl; } return 0; }
相关文章推荐
- HYSBZ 3196 Tyvj 1730 二逼平衡树(树套树)
- Spring mvc 配置详解
- MySQL服务基础
- TCP/IP协议之IP协议详解
- C++:标准IO(输入输出)
- iOS之使用ZbarSDK实现扫描二维码以及条形码功能
- 浅析JTable与TableModel、TableCellRenderer、TableCellEditor接口——使用JComboBox显示单元格的值
- LCD电子书项目(七)
- 分页+新建+跳转+最后页
- lintcode-medium-Permutation Sequence
- POJ题目分类(转)
- Marshmallow and User Data
- 变量
- Spring MVC 知识点集合
- dipole antenna simulation by FEKO
- 计算机科学专业必读的44册经典著作
- java中ObjectOutputStream和ObjectInputStream的使用
- Android图片加载框架Picasso最全使用教程 五
- 面试题5 从尾到头打印链表
- R语言︱文本挖掘之中文分词包——Rwordseg包(原理、功能、详解)