用map做的,很简单
code:
#include <map> #include <cstdio> #include <cstring> #include <iostream> using namespace std; map<string,string> dict; map<string,string>::iterator it; char tmp1[25],tmp2[25],word[25]; char sent[3030]; int main() { //freopen("output.txt","w",stdout); scanf("%s",tmp1); while(scanf("%s",tmp1)) { if(!strcmp(tmp1,"END"))break; scanf("%s",tmp2); dict[tmp2]=tmp1; } scanf("%s",tmp1);getchar(); int len,i,j; while(gets(sent)) { if(!strcmp(sent,"END"))break; len=strlen(sent); j=0; for(i=0;i<len;i++){ if('a'<=sent[i] && sent[i]<='z') { word[j++]=sent[i]; } else{ word[j]='\0'; it=dict.find(word); if(it!=dict.end()) cout<< it->second; else printf("%s",word); printf("%c",sent[i]); j=0; } } puts(""); } return 0; }