//80分.....不知道哪有问题了.......
#include<iostream>
#include<sstream>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
using namespace std;
const int N = 100+5;
struct Node{
string pre;
string nxt;
}q[N];
bool Match(Node t, string s){
string s1 = t.pre;
vector<string> v;
for(int i=0, j=0; s[j] || s1[i]; ){
if(s1[i] == '\0' || s[j] == '\0')//加了该行 80....然后剩下运行错误....
return false;
if(s1[i] == s[j]){
i++;
j++;
} else if(s1[i] != '<'){
return false;
} else if(s1[i+1]=='i'){
int tmp = 0;
while(isdigit(s[j])){
tmp *= 10;
tmp += s[j]-'0';
j++;
}
if(s[j] != '/'){
return false;
}
i += 5;
//cout << "digit" << tmp << endl;
char *st;
sprintf(st, "%d", tmp);
v.push_back(st);
}else if(s1[i+1]=='s'){
string tmp="";
while(isalpha(s[j]) && s[j]!='/'){
tmp += s[j];
j++;
}
i += 5;
//cout << "str" << tmp << endl;
v.push_back(tmp);
}else if(s1[i+1] == 'p'){
string tmp=s.substr(j);
v.push_back(tmp);
i += 6;
//cout << "path" << tmp << endl;
j = s.length();
}
}
cout << t.nxt << " ";
for(int i=0; i<v.size(); i++){
cout << v[i] << " ";
}
cout << endl;
return true;
}
int main()
{
int n, m;
cin >> n >> m;
cin.get();
string s;
for(int i=0; i<n; i++){
getline(cin, s);
stringstream ss(s);
ss >> s;
q[i].pre = s;
ss >> s;
q[i].nxt = s;
}
string s1, s2;
for(int i=0; i<m; i++){
getline(cin, s);
bool flag = false;
for(int j=0; j<n; j++){
// cout << "match " << q[j].pre << ":" << s << endl;
if(Match(q[j], s)){
flag = true;
break;
}
}
if(!flag){
cout << "404" << endl;
}
}
return 0;
}
//只有70分 暂时想不到哪里没想到
#include<iostream>
#include<sstream>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
using namespace std;
const int N = 200+5;
struct Node{
string pre;
string nxt;
}q[N];
bool Match(Node t, string s){
string s1 = t.pre;
int cnt = 0;
vector<string> v;
for(int i=0, j=0; s[j] || s1[i]; ){
if(s1[i] == s[j]){
cnt++;
i++;
j++;
} else if(s1[i] != '<'){
return false;
} else if(s1[++i]=='i'){
int tmp = 0;
while(isdigit(s[j])){
tmp *= 10;
tmp += s[j]-'0';
j++;
}
if(s[j] != '/'){
return false;
}
i += 4;
//cout << "digit" << tmp << endl;
char *st;
sprintf(st, "%d", tmp);
v.push_back(st);
}else if(s1[i]=='s'){
string tmp="";
while(isalpha(s[j]) && s[j]!='/'){
tmp += s[j];
j++;
}
i += 4;
//cout << "str" << tmp << endl;
v.push_back(tmp);
}else if(s1[i] == 'p'){
string tmp=s.substr(j);
v.push_back(tmp);
i += 5;
//cout << "path" << tmp << endl;
j = s.length();
}
}
cout << t.nxt << " ";
for(int i=0; i<v.size(); i++){
cout << v[i] << " ";
}
cout << endl;
return true;
}
int main()
{
int n, m;
cin >> n >> m;
cin.get();
string s;
for(int i=0; i<n; i++){
getline(cin, s);
stringstream ss(s);
ss >> s;
q[i].pre = s;
ss >> s;
q[i].nxt = s;
}
string s1, s2;
for(int i=0; i<m; i++){
getline(cin, s);
bool flag = false;
for(int j=0; j<n; j++){
// cout << "match " << q[j].pre << ":" << s << endl;
if(Match(q[j], s)){
flag = true;
break;
}
}
if(!flag){
cout << "404" << endl;
}
}
return 0;
}