用map做的,
#include <iostream>
#include <map>
#include <string>
#include <cctype>
using namespace std;
map<string ,string> m;
int main()
{
string mar,earth,s;
cin>>s;
while(cin>>earth)
{
if(earth=="END")
break;
cin>>mar;
m[mar]=earth;
}
getchar();
string str,code;
int i,j;
while(getline(cin,str))
{
code="";
if(str=="END") break;
if(str=="START") continue;
for(i=0;i<str.size();i++)
{
if(isalpha(str[i]))
{
code+=str[i];
if(!isalpha(str[i+1]))
{
if(m[code]!="")
cout<<m[code];
else
cout<<code;
code="";
}
}
else
cout<<str[i];
}
cout<<endl;
}
return 0;
}
本文介绍了一个使用C++实现的简易翻译器程序。该程序利用标准模板库中的map来存储词汇及其对应的翻译,并通过读取输入进行词汇翻译。文章展示了如何构建map以关联地球语言词汇与火星语言词汇,并在输入文本中进行查找替换。
620

被折叠的 条评论
为什么被折叠?



