题目大意:
大概就要把句子翻译过来。给出了字典,和要翻译的句子。
用map<string ,string > 就可以模拟字典。
用一个临时的字符数组扫描。
在模拟的时候,如果碰到不是英文字母的。就把临时数组输出,然后再输出这个字符就可以了。
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <map>
#include <string>
using namespace std;
string str;
map<string,string>mp;
string ans;
char s[10000];
char tmp[1000];
int main()
{
cin>>str;
while(cin>>str)
{
if(str=="END")break;
else
{
cin>>ans;
mp[ans]=str;
}
}
getchar();
while(gets(s)!=NULL)
{
if(strcmp(s,"START")==0)continue;
if(s[0]=='E' && s[1]=='N' && s[2]=='D')break;
else
{
int len=strlen(s);
int pos=0;
while(pos<len)
{
int top=0;
while(1)
{
if(s[pos]<='z' && s[pos]>='a')
tmp[top++]=s[pos++];
else
{
//printf("%c",s[pos++]);
break;
}
}
tmp[top]='\0';
if(top!=0)
{
ans=tmp;
if(mp[ans]=="")cout<<ans;
else
{
cout<<mp[ans];
}
}
else
printf("%c",s[pos++]);
}
}
puts("");
}
return 0;
}