poj 2503 Babelfish
2015-08-14 11:26
363 查看
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
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
#include <iostream> #include <cstdio> #include <cstring> #include <map> #include <cstdlib> #include <queue> #include <stack> #include <cmath> #define LL long long #define INF 0x3f3f3f3f using namespace std; map<string,string> S; int main() { char str[60]; while(gets(str) && str[0]) { char *p = str; char *q = strchr(str,' '); *q = 0; q++; int len1 = strlen(p); int len2 = strlen(q); string key,val; key.resize(len1); val.resize(len2); for(int i=0; i<len1; i++) key[i] = p[i]; for(int i=0; i<len2; i++) val[i] = q[i]; S[val] = key; } while(cin>>str) { int len = strlen(str); string key; key.resize(len); for(int i=0; i<len; i++) key[i] = str[i]; if(S[key].size()) cout<<S[key]<<endl; else printf("eh\n"); } return 0; }
相关文章推荐
- 励精图治---Concurrency---小结
- c语言中各类型所占字节,及输出模式
- hive的异常
- spring <context:annotation-config> 跟 <context:component-scan>诠释及区别
- 中小型网站网络文件系统-NFS部署搭建
- 算法思想篇(5)————贪心算法
- Android Studio导入JAR包(以ButterKnife为例)
- 字符串分隔(java)
- leaks will report false positives while the environment variable NSZombiesEnable is active
- hdu 1358 Period(kmp求一个串的重复子串)
- Codeforces 570 B. Simple Game ( 概率 )
- Android fragment 只让一个fragment支持横屏
- 使用4.3.11版本的hibernate结合druid连接池遇到的问题
- ubuntu 14.04 编译android4.0 出现gcc-version.sh: line 11: cc: command not found错误解决方法
- A题之变态青蛙跳
- 三天打渔,俩天晒网(C++实现)
- BZOJ1008[HNOI2008]越狱
- POJ 1094 Sorting It All Out (拓扑排序)
- java设计模式----原型模式
- POJ 2533 Longest Ordered Subsequence