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

翻译题(map使用)

时间:2015-06-03 13:34:04      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:

What Are You Talking About

点我

Problem Description
Ignatius is so lucky that he met a Martian yesterday. But he didn‘t know the language the Martians use. The Martian gives him a history book of Mars and a dictionary when it leaves. Now Ignatius want to translate the history book into English. Can you help him?
 
Input
The problem has only one test case, the test case consists of two parts, the dictionary part and the book part. The dictionary part starts with a single line contains a string "START", this string should be ignored, then some lines follow, each line contains two strings, the first one is a word in English, the second one is the corresponding word in Martian‘s language. A line with a single string "END" indicates the end of the directory part, and this string should be ignored. The book part starts with a single line contains a string "START", this string should be ignored, then an article written in Martian‘s language. You should translate the article into English with the dictionary. If you find the word in the dictionary you should translate it and write the new word into your translation, if you can‘t find the word in the dictionary you do not have to translate it, and just copy the old word to your translation. Space(‘ ‘), tab(‘\t‘), enter(‘\n‘) and all the punctuation should not be translated. A line with a single string "END" indicates the end of the book part, and that‘s also the end of the input. All the words are in the lowercase, and each word will contain at most 10 characters, and each line will contain at most 3000 characters.
 
Output
In this problem, you have to output the translation of the history book.
 
Sample Input
START
from fiwo
hello difh
mars riwosf
earth fnnvk
like fiiwj
END START
difh, i‘m fiwo riwosf.
i fiiwj fnnvk! END
 
Sample Output
hello, i‘m from mars. i like earth!
 
一道翻译转换题,学会了map使用。
 1 #include<iostream>
 2 #include<map>
 3 #include<cstdio>
 4 #include<algorithm>
 5 #include<string>
 6 #include<cstring>
 7 using namespace std;
 8 int main()
 9 {
10     map<string,string>mp;
11     int i=0,j,k;
12     char s1[15],s2[15];
13     char a[11];
14     char ch;
15     char buf[15];
16    // freopen("in.txt","r",stdin);
17     gets(a);
18     while(scanf("%s",s1))
19     {
20         if(0==strcmp(s1,"END"))
21             break;
22         else
23         {
24              scanf("%s",s2);
25              mp[s2]=s1;
26         }
27     }
28     getchar();
29     gets(a);
30     while(scanf("%c",&ch)==1)
31     {
32         if(isalpha(ch))
33         {
34             buf[i++]=ch;
35         }
36         else
37         {
38             buf[i]=\0;
39             i=0;
40             if(strcmp(buf,"END")==0)
41                 break;
42             if(mp.find(buf)!=mp.end())
43                 cout<<mp[buf];
44             else
45                 printf("%s",buf);
46             printf("%c",ch);
47         }
48 
49     }
50     return 0;
51 }

 

翻译题(map使用)

标签:

原文地址:http://www.cnblogs.com/a1225234/p/4548858.html

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