# CCF 201803-3 大模拟

### AC代码：

#include <iostream>
#include <cstring>
using namespace std;

bool solve(string str1, string str2, bool flag) {
int index1 = 0, index2 = 0, len1 = str1.size(), len2 = str2.size();
while (index1 < len1 and index2 < len2) {
if (str1[index1] == str2[index2]) {
index1++, index2++;
continue;
}
if (str1[index1++] != '<')
return false;
if (flag == true)
cout << " ";
if (str1[index1] == 'i') {//int
bool flag2 = false;
while (index2 < len2 and isdigit(str2[index2])) {
if (str2[index2] > '0')
flag2 = true;
if (flag and flag2)
cout << str2[index2];
index2++;
}
if (flag2 == false)
return false;
index1 += 4;
continue;
}
else if (str1[index1] == 's') {//str
bool flag2 = false;
while (index2 < len2 and str2[index2] != '/') {
flag2 = true;
if (flag and flag2)
cout << str2[index2];
index2++;
}
if (flag2 == false)
return false;
index1 += 4;
continue;
}
else if (str1[index1] == 'p') {//path
while (flag and index2 < len2)
cout << str2[index2++];
return true;
}
}
return index1 == len1 && index2 == len2;
}
int main(void) {
int n, m;
cin >> n >> m;
string str[110], name[110], temp;
for (int i = 0; i < n; i++)
cin >> str[i] >> name[i];

for (int i = 0; i < m; i++) {
cin >> temp;
bool flag = true;
for (int i = 0; i < n && flag; i++) {
if (solve(str[i], temp, false)) {
flag = false;
cout << name[i];
solve(str[i], temp, true);
}
}
if (flag == true)
cout << "404";
cout << endl;
}
return 0;
}