http://acm.hdu.edu.cn/showproblem.php?pid=1075
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/204800 K (Java/Others)
Total Submission(s): 14876 Accepted Submission(s): 4783
题目大意:给你一些字符串和对应的字符串,然后给出一些话,然后根据之前的字符串来对应输出,如果没有对应,则输出原来的字符串。
代码:
1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <cstring> 5 #include <algorithm> 6 #include <string> 7 #include <map> 8 using namespace std; 9 10 #define MAX 0x7fffffff 11 #define N 3000 12 13 map<string,string> m; 14 map<string,string>::iterator it; 15 16 int main(){ 17 //freopen("D:\\input.in","r",stdin); 18 //freopen("D:\\output.out","w",stdout); 19 char s1[N],s2[N]; 20 gets(s1); 21 while(1){ 22 scanf("%s",s1); 23 if(s1[0]==‘E‘){ 24 break; 25 }else{ 26 scanf("%s",s2); 27 m.insert(pair<string,string>(string(s2),string(s1))); 28 } 29 } 30 gets(s1); 31 gets(s1); 32 while(1){ 33 gets(s1); 34 if(s1[0]==‘E‘){ 35 break; 36 }else{ 37 int len=strlen(s1),step=0; 38 for(int i=0;i<len;i++){ 39 if(s1[i]>=‘a‘&&s2[i]<=‘z‘){ 40 s2[step++]=s1[i]; 41 continue; 42 }else{ 43 s2[step]=‘\0‘; 44 it=m.find(string(s2)); 45 if(it!=m.end()){ 46 printf("%s",(*it).second.c_str()); 47 }else{ 48 printf("%s",s2); 49 } 50 step=0; 51 putchar(s1[i]); 52 } 53 } 54 puts(""); 55 } 56 } 57 return 0; 58 }
hdoj1075-What Are You Talking About 【map】
原文:http://www.cnblogs.com/jiu0821/p/4302028.html