#include<cstdio> #include<iostream> #include<algorithm> #include<vector> #include<string> #include<queue> #include<map> using namespace std; string temp[105]; map<string,string> mp; int main() { int n,m; cin>>m>>n; getchar(); //吸收一个换行 for(int i=0;i<m;i++) { getline(cin,temp[i]); } string name,value,str; for(int i=0;i<n;i++) { getline(cin,str); for(int j=0;j<str.length();j++) { if(str[j]==' ') { name = str.substr(0,j); value = str.substr(j+2,str.length()-j-3); break; } } mp[name] = value; //cout<<name<<" "<<mp[name]<<endl; } for(int k=0;k<m;k++) { for(int i=0;i<temp[k].length();i++) { if(i+1<temp[k].length() &&temp[k][i] == '{' && temp[k][i+1] == '{' ) { int j,t; string nm; for(j=i+2;j<temp[k].length();j++) { if(j+1<temp[k].length() &&temp[k][j] == '}' && temp[k][j+1] == '}' ) { nm = temp[k].substr(i+2,j-1-i-2+1); t = j+1; break; } } for(j=0;j<nm.length();j++) //去首部空格 ,只考虑首尾有空格的情况 if(nm[j]!=' ') break; int end; for(end = nm.length()-1;end>=j;end--) //去尾部 if(nm[end]!=' ') break; if(nm[j]>='0' && nm[j]<='9') { cout<<temp[k][i]; continue; //变量名不合法,当作非特殊标记处理 } int begin = j; for(j;j<=end;j++) { if((nm[j]>='0' && nm[j]<='9')||(nm[j]>='a' && nm[j]<='z') || (nm[j]>='A' && nm[j]<='Z') || nm[j]=='_') continue; else break; } if(j != end+1) { cout<<temp[k][i]; continue; //变量名不合法,当作非特殊标记处理 } i = t; //合法 nm = nm.substr(begin,end-begin+1); if(mp[nm] == "") cout<<""; else cout<<mp[nm]; } else cout<<temp[k][i]; } cout<<endl; } return 0; }