POJ2503 Babelfish(Map键值对的应用)
2015-06-02 11:47
281 查看
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.
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 35424 | Accepted: 15146 |
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.
解题思路:
裸Map的运用,直接上代码:AC代码:
#include<iostream> #include<string> #include<map> #include<cstdio> using namespace std; int main() { map<string,string> M; string a; //freopen("1.txt","r",stdin); while(getline(cin,a)) { string first; string second; if(0 == a.length()) { break; } int i = a.find_first_of(' '); first = a.substr(0,i); //0 - i int j = a.find_first_not_of(' ',i); second = a.substr(j,a.length() - j); //j开始共a.length - j位 M[second] = first; } string b; while(getline(cin,b)) { if(M.count(b)) { string c = M[b]; printf("%s\n",c.c_str()); //cout<<M[b]<<endl; } else { printf("eh\n"); //cout<<"eh"<<endl; } } return 0; }
相关文章推荐
- 服务器获取准确IP
- 设置jfreechart时间序列图时间轴间距和格式
- iOS SDK详解之UIDevice(系统版本,设备型号...)
- MODBUS的字符间隔时间怎么设置
- Spring整个Ibatis之SqlMapClientDaoSupport
- 能立刻激怒程序员的10句逗逼话==程序员的笑话
- android:网页访问Activity出现错误:error unknown url scheme
- node.js2
- node.js
- C#中锁定Word内容,样把人家的锁定内容破解了
- MD5 加密
- ThinkPHP开发笔记-用户登录注册
- 深入理解Java Class文件格式(六)
- 线性回归
- XenAPI DOC
- hdu2612---Find a way
- [转贴]搜索引擎优化(SEO)菜鸟版@搜索引擎研究专案
- 解析properties文件
- 深入理解Java Class文件格式(五)
- AndroidStudio中aar文件引用