码迷,mamicode.com
首页 > 其他好文 > 详细

POJ2503——Babelfish(map映射+string字符串)

时间:2014-10-29 23:47:14      阅读:350      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   io   color   os   ar   for   sp   

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

atcay
ittenkay
oopslay
Sample Output
cat
eh
loops

题目大意:

    一本猫与人类语言的翻译字典,输入一个猫的语言,输出人的语言,若没有输出eh。

解题思路:

    map映射水过。

Code:

 1 /*************************************************************************
 2     > File Name: poj2503.cpp
 3     > Author: Enumz
 4     > Mail: 369372123@qq.com
 5     > Created Time: 2014年10月19日 星期日 16时54分07秒
 6  ************************************************************************/
 7 
 8 #include<iostream>
 9 #include<cstdio>
10 #include<cstdlib>
11 #include<string>
12 #include<cstring>
13 #include<list>
14 #include<queue>
15 #include<stack>
16 #include<map>
17 #include<set>
18 #include<algorithm>
19 #define MAXN 100000
20 using namespace std;
21 map <string,string> m;
22 void Solve()
23 {
24     char tmp1[15];
25     string str1,str2;
26     while (gets(tmp1)&&strlen(tmp1))
27     {
28         int k=0;
29         str1=str2="";
30         while (1)
31             if (tmp1[k]== )
32             {
33                 tmp1[k]=\0;
34                 break;
35             }
36             else k++;
37         str1+=tmp1;
38         str2+=tmp1+k+1;
39         m[str2]=str1;
40     }
41     while (cin>>str1)
42         if (m[str1].size())
43             cout<<m[str1]<<endl;
44         else
45             cout<<"eh"<<endl;
46     return ;
47 }
48 int main()
49 {
50     Solve();
51     return 0;
52 }

 

POJ2503——Babelfish(map映射+string字符串)

标签:des   style   blog   io   color   os   ar   for   sp   

原文地址:http://www.cnblogs.com/Enumz/p/4060604.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!