#include <map>
#include <iostream>
#include <string>
#include <string.h>
using namespace std;
int main()
{
freopen("1075.txt", "r", stdin);
string first;
string second;
cin >> first;
map<string, string> word;
while(cin >> first, first != "END")
{
cin >> second;
word[second] = first;
}
map<string, string>::iterator it;
string s;
cin >> s;
char ss[3005];
int len;
getchar();
string w, ans;
while(gets(ss), strcmp(ss, "END"))
{
len = strlen(ss);
w = "";
ans = "";
for(int i = 0; i < len; i++)
{
if(isalpha(ss[i]))
w += ss[i];
else
{
it = word.find(w);
if(it != word.end())
ans += (*it).second;
else
ans += w;
w = "";
ans += ss[i];
}
}
cout << ans.c_str() << endl;
}
return 0;
}
字典树的程序效率高很多,等会了,用字典树写
使用Map实现文本替换

9万+

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



