开门见山,直接放一百分代码:
c
#include<iostream>
#include<algorithm>
#include<cstring>
#include<bits/stdc++.h>
using namespace std;
const int N = 2e4 + 10;
string a[1010];
unordered_map<string , string> mp;
void check(string &s)
{
int len = s.size();
string res = "";
string z;
for(int i = 0 ; i < len ; i++)
{
if(s[i] == '{' && s[i + 1] == '{')
{
int j = i + 3;
string k="";
while(s[j] != ' ')
{
k += s[j];
j++;
}
if(mp.count(k) == 0){
i = j + 2;
continue;
}
z = mp[k];
i = j + 2;
res += z;
continue;
}
res += s[i];
}
s = res;
}
int main()
{
int m , n;
cin >> m >> n;
getchar();
for(int i = 1 ; i <= m ; i++)
{
getline(cin , a[i]);
}
for(int i = 1 ; i <= n ; i++){
string k;
string z;
cin >> k;
getline(cin , z);
string zz="";
for(int j = 2 ; j < z.size()-1 ; j++)
zz += z[j];
mp[k] = zz;
}
for(int i = 1 ; i <= m ; i++)
{
check(a[i]);
cout << a[i] << endl;
}
return 0;
}