HDU 1075 字符串映射(map)

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!

给你字符串以及它的映射,提问任意一个映射它真实的字符串是什么

 

 1 #include<stdio.h>
 2 #include<algorithm>
 3 #include<iostream>
 4 #include<string>
 5 #include<map>
 6 
 7 using namespace std;
 8 
 9 map<string,string>mp;
10 int main()
11 {
12 
13     mp.clear();
14     string str1,str2;
15     cin>>str1;
16     while(cin>>str1)
17     {
18         if(str1=="END")break;
19         cin>>str2;
20         mp[str2]=str1;
21     }
22     cin>>str1;
23     char ch;
24     ch=getchar();
25     str1="";
26     while(1)
27     {
28         while(1)
29         {
30             scanf("%c",&ch);
31             if(!((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z')))break;
32             str1+=ch;
33         }
34         if(str1=="END")break;
35         if(mp.find(str1)==mp.end())cout<<str1;
36         else cout<<mp[str1];
37         str1="";
38         printf("%c",ch);
39     }
40     return 0;
41 }
View Code

 

posted @ 2015-05-12 17:11  __Meng  阅读(273)  评论(0编辑  收藏  举报