fork download
  1. #import<bits/stdc++.h>
  2. #define a first
  3. #define b second
  4. #define c(s);else if(x.a==s)
  5. #define e(n)(n=regex_replace(n,q,"$1")).empty()
  6. #define f(n)for(;getline(cin,n),e(n););
  7. #define i p.top().a
  8. #define j!p.empty()
  9. #define w,back_inserter
  10. using namespace std;using g=string;using h=istream_iterator<g>;using s=vector<g>;using A=array<g,3>;using t=pair<pair<long,A>,s>;map<g,A>m;map<g,long>n;stack<t>p;regex q("^ *(.*?) *(#.*)?$");main(){bool z;for(g W,X,Y,Z;getline(cin,W);)if(!e(W))for(p.push(t{{0,{{W,"",""}}},{}});z=j;){pair<g,s>x;istringstream S(i.b[i.a]);S>>x.a;copy(h(S),h()w(x.b));s o;transform(&x.b[0],&*end(x.b)w(o),[](g y){int v=atoi(&y[0]);return v>0?p.top().b[v-1]:y;});if(0)c("")c("p")cout<<o[0]<<" = "<<n[o[0]]<<'\n'c("i")n[o[0]]++c("d")n[o[0]]-=z=n[o[0]]c("a"){f(X)f(Y)f(Z)m.insert(make_pair(o[0],A{{X,Y,Z}}));}else{p.push(t{{0,m[x.a]},o});continue;}while(j&&i.a)p.pop();j?i.a-=~!z:0;}}
Success #stdin #stdout 0s 4340KB
stdin
i malamute
p malamute
d malamute    #success
p malamute
d malamute    #failure
p malamute
d akita       #failure
p akita
stdout
malamute = 1
malamute = 0
malamute = 0
akita = 0