转载的,进行了部分修改,原网站http://blog.csdn.net/chang_mu/article/details/38469715
#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <map>
using namespace std;
const int maxn=1e5+1;
const int inf=0x3f3f3f3f;
#include <cstdio>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <map>
using namespace std;
const int maxn=1e5+1;
const int inf=0x3f3f3f3f;
int main()
{
char buf[12], s1[12], s2[12], ch;
map<string, string> mp;
int id = 0;
gets(buf); //不要 START
while(scanf("%s%s", s1, s2), strcmp(s1, "END"))
{
mp[s2] = s1;
}
getchar();//刷新
while(scanf("%c", &ch))//一个字母一个字母的输入,免去空格和别的
{
if(isalpha(ch)) buf[id++] = ch;//把拆出来的字母重新组成单词。
else
{
buf[id] = '\0'; id = 0;
if(strcmp(buf, "END") == 0) break;
if(mp.find(buf) != mp.end())
{
printf("%s", mp[buf].c_str());//为了用printf,用.c_str()
}
else printf("%s", buf);
putchar(ch);//这是最后的标点符号
}
}
}
{
if(isalpha(ch)) buf[id++] = ch;//把拆出来的字母重新组成单词。
else
{
buf[id] = '\0'; id = 0;
if(strcmp(buf, "END") == 0) break;
if(mp.find(buf) != mp.end())
{
printf("%s", mp[buf].c_str());//为了用printf,用.c_str()
}
else printf("%s", buf);
putchar(ch);//这是最后的标点符号
}
}
}