STUDENT00 @ 2022-08-23 18:25:27
哪位大佬可以帮帮我呢?
#include<bits/stdc++.h>
using namespace std;
string str;
map<string,int> f;
struct node{
int len,a[110]={0};
};
vector<node> v;
int k;
int read(int k){
stack<int> q;
int t=0,i=k;
do{
if(str[i]>='0'&&str[i]<='9'){
while(str[i]>='0'&&str[i]<='9'){
t=t*10+str[i]-'0';
i++;
}
i--;
}else if(str[i]!='['&&str[i]!=']'){
string p="";
while(str[i]!='['){
p+=str[i];
i++;
}
q.push(f[p]);
}else if(str[i]==']'){
if(v[q.top()].len<=t) return -1;
t=v[q.top()].a[t];
q.pop();
}
i++;
}while(!q.empty());
return t;
}
int main(){
node q;
v.push_back(q);
while(getline(cin,str)){
if(str[0]=='i'&&str[1]=='n'&&str[2]=='t'&&str[3]==' '){
string p="";
int i;
for(i=4;str[i]!='[';i++) p+=str[i];
int num=read(i+1);
k++;
f[p]=k;
node q;
q.len=num;
v.push_back(q);
}else if(str[0]=='c'&&str[1]=='o'&&str[2]=='u'&&str[3]=='t'&&str[4]==' '){
int num=read(5);
if(num==-1){
printf("-1");
return 0;
}else printf("%d\n",num);
}else{
string p="";
int i;
for(i=0;str[i]!='[';i++) p+=str[i];
int num=read(i+1);
if(num==-1||v[f[p]].len<=num){
printf("-1");
return 0;
}
v[f[p]].a[num]=read(str.find(" ")+1);
}
}
return 0;
}