按火星语建trie树 , 每个节点存一个地球语
#include<string>
#include<iostream>
#define N 1000050
using namespace std;
struct Trie{int ch[26],flag; string s;}t[N];
int tot;
void Insert(string s,string ss){
int len = ss.length(),now=0;
for(int i=0;i<len;i++){
int pos = ss[i] - 'a';
if(!t[now].ch[pos]) t[now].ch[pos] = ++tot;
now = t[now].ch[pos];
} t[now].flag = 1; t[now].s = s;
}
string quary(string s){
int len = s.length(),now=0;
for(int i=0;i<len;i++){
int pos = s[i] - 'a';
if(!t[now].ch[pos]) return s;
now = t[now].ch[pos];
}
if(t[now].flag) return t[now].s;
else return s;
}
int main(){
string s; cin>>s;
while(s!="END"){
cin>>s; string ss; cin>>ss;
Insert(s,ss);
} cin>>s; char ch=getchar(); while(1){
getline(cin,s); int len = s.size();
if(s=="END") break; string tmp; tmp.clear();
for(int i=0;i<=len;i++){
if('a'<=s[i] && s[i]<='z') tmp += s[i];
else{
cout<<quary(tmp);
cout<<s[i]; tmp.clear();
}
} printf("\n");
} return 0;
}