HDUOJ---What Are You Talking About

What Are You Talking About

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K (Java/Others) Total Submission(s): 10963    Accepted Submission(s): 3521

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?


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.


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!


Huge input, scanf is recommended.



  map 容器的应用....map[aa]=bb;



 1 #pragma warning (disable:4786)
 2 #include<iostream>
 3 #include<map>
 4 #include<string>
 5 #include<cstdio>
 6 #include<cstring>
 7 #include<cstdlib>
 8 using namespace std;
 9 const int maxn =3002;
10 char aa[maxn+1],bb[15];
11 int main()
12 {
13     scanf("%*s");
14     map<string,string>msg;
15     while(scanf("%s",aa),strcmp(aa,"END"))
16     {
17       scanf("%s",bb);
18         msg[bb]=aa;
19     }
20       scanf("%*s");
21       getchar();
22       map<string,string>::iterator it;
23       memset(bb,'\0',sizeof(bb));
24       while(cin.getline(aa,3002),strcmp(aa,"END"))
25       {
26           int step=0;
27           for(int i=0;i<strlen(aa);i++)
28           {
29             if((aa[i]<'a'||aa[i]>'z'))
30             {
31              if(step)
32              {
33                 it=msg.find(bb);
34                 if(it!=msg.end())
35                 {
36                   cout<<(*it).second;
37                 }
38                 else
39                     printf("%s",bb);
40                 step=0;
41                 memset(bb,'\0',sizeof(bb));
42              }
43                 cout<<aa[i];
44             }
45             else
46             {
47               bb[step++]=aa[i];
48             }
49           }
50           puts("");
51       }
52     return 0;
53 }




0 条评论
登录 后参与评论