_ldyex_ @ 2024-02-16 14:09:07
#include<bits/stdc++.h>
using namespace std;
const int maxn = 105;
int a[maxn][maxn], tot, id, len[maxn];
map<string, int> mp;
string op, s, name;
string getname(string s){
string name = "";
for(int i = 0; i < s.size() && s[i] != '['; i++) name += s[i];
return name;
}
int getnum(string s, bool f){
bool flag = 0;
for(int i = 0; i < s.size(); i++){
if(s[i] < '0' || s[i] > '9'){
flag = 1;
break;
}
}
if(!flag) return atoi(s.c_str());
int i;
string nums = "";
for(i = 0; i < s.size() && s[i] != '['; i++);
i++;
for(; i < s.size() && s[i] != ']'; i++) nums += s[i];
int _id = getnum(nums, 1);
return (f == 1 ? a[mp[name]][_id] : _id);
}
int main(){
while(cin >> op){
cin >> s;
if(op == "int"){
name = getname(s);
mp[name] = ++tot;
len[tot] = getnum(s, 0) - 1;
}
else if(op == "cout"){
name = getname(s);
id = getnum(s, 0);
if(id > len[mp[name]] || id < 0){
cout << -1;
return 0;
}
else{
cout << a[mp[name]][id] << '\n';
}
}
else{
name = getname(op);
id = getnum(op, 0);
if(id > len[mp[name]] || id < 0){
cout << -1;
return 0;
}
else{
a[mp[name]][id] = (getname(s) == s ? atoi(s.c_str()) : a[mp[getname(s)]][getnum(s, 0)]);
}
}
}
return 0;
}