代码:
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
string a[101], b[101];
cin >> n;
// cout << n << endl;
for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
string s;
bool flag = 0;
int first = 0, en= 0;
cin >> s;
string s2 = "";
int e = s.length();
string s1 = s;
for(int i = 0; i < e; i++){
if(i == e - 1)
en = e - 1;
// cout << first << endl;
// cout << i << " ";
if(s1[i] >= 'a' && s1[i] <= 'z' && flag == 0){
first = i;
flag = 1;
continue;
}
if(s1[i] >= 'a' && s1[i] <= 'z')
continue;
// if(!(s1[i] >= 'a' && s1[i] <= 'z'))
if(!(s1[i] >= 'a' && s1[i] <= 'z')&&flag !=0 && s1[i - 1] >= 'a' && s1[i - 1] <= 'z'){
en = i - 1;
flag = 0;
// s2 += s1[i];
}
if(s1[i - 1] >= 'a' && s1[i - 1] <= 'z'){
string w = s1.substr(first, en - first+1);
// cout << w << endl;
// cout << first << endl;
bool flag1 = 0;
for(int j = 0; j < n; j++){
if((w == a[j])&&(en!=0)){
// s2 = s.replace(first, en - first + 1, b[j]);
// s = "";
// s += s1;
s2 += b[j];
// cout<<first<<en<<endl;
/// cout<<s<<endl;
flag1 = 1;
break;
}
}
if((flag1 == 0)&&(en!=0)){
s2 += "UNK";
// cout<<first<<en<<endl;
}
}
if(!(s1[i] >= 'a' && s1[i] <= 'z')){
s2 += s1[i];
}
}
// cout << first << " " << en << " " << endl;
string w = s1.substr(first, en - first+1);
bool flag1 = 0;
for(int j = 0; j < n; j++){
if((w == a[j])&&(en!=0)){
// s2 = s.replace(first, en - first + 1, b[j]);
// s = "";
// s += s1;
s2 += b[j];
// cout<<first<<en<<endl;
/// cout<<s<<endl;
flag1 = 1;
break;
}
}
if((flag1 == 0)&&(en!=0)){
s2 += "UNK";
// cout<<first<<en<<endl;
}
cout << s2;
return 0;
}