#include <bits/stdc++.h>
using ll = long long;
constexpr int PAIR = 0;
constexpr int INT = 1;
constexpr int DOUBLE = 2;
struct Type {
int base;
Type *first;
Type *second;
};
Type *readType(const std::string &s, int &i) {
Type *t = new Type;
if (s[i] == 'i') {
i += 3;
t->base = INT;
} else if (s[i] == 'd') {
i += 6;
t->base = DOUBLE;
} else {
i += 5;
t->first = readType(s, i);
i++;
t->second = readType(s, i);
i++;
}
return t;
}
void printType(Type* t) {
if (t->base == INT) {
std::cout << "int";
}
else if (t->base == DOUBLE) {
std::cout << "double";
}
else {
std::cout << "pair<";
printType(t->first);
std::cout << ",";
printType(t->second);
std::cout << ">";
}
}
int main() {
std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0);
int n, q;
std::cin >> n >> q;
std::vector<Type *> type(n);
std::vector<std::string> name(n);
std::map<std::string, int> id;
for (int i = 0; i < n; i++) {
std::string t;
std::cin >> t >> name[i];
name[i].pop_back();
int cur = 0;
type[i] = readType(t, cur);
id[name[i]] = i;
}
while (q--) {
std::string s;
std::cin >> s;
s += ".";
std::vector<std::string> a;
for (int i = 0; i < s.size(); i++) {
int j = s.find('.', i);
a.push_back(s.substr(i, j - i));
i = j;
}
Type* t = type[id[a[0]]];
for (int i = 1; i < a.size(); i++) {
if (a[i] == "first") {
t = t->first;
}
else {
t = t->second;
}
}
printType(t);
std::cout << "\n";
}
return 0;
}
03-07
2458
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-02