# 11120: 【原1120】二哥的嘲讽

### 题目描述

author: Huihuang Zheng 原OJ链接：https://acm.sjtu.edu.cn/OnlineJudge-old/problem/1120

## Description

C++中，在花括号中再次声明一个同名变量时，会有以下特性：

``````int x = 0;
{
int x = 1;
printf("%d\n", x); // 输出1，不再是上一层x
x = 3;
printf("%d\n", x); // 输出3
}
printf("%d\n", x); // 输出0 花括号里的变量x空间被释放后不存在了
``````

## Sample Input

``````3 12
1 1
1 2
2 3
0 1
-1
1 4
0 2
0 1
0 3
-2
0 1
0 3
``````

## Sample Output

``````2
3
4
0
2
0
``````

## FineArtz's solution

``````/* 二哥的嘲讽 */
#include <iostream>
using namespace std;

struct Node{
int data = 0;
int layer = 0;
Node *next = nullptr;

Node(int d = 0, int l = 0, Node *n = nullptr)
: data(d), layer(l), next(n) {}
};

int size = 0;

void push(int d, int l){
Node *p = new Node(d, l, head);
++size;
}

int top(){
}

int topLayer(){
}

void pop(){
delete p;
}

void resetTop(int x){
}

void clear(){
while (p){
q = p;
p = p->next;
delete q;
}
}
};

int n, k, layer = 0;

int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
while (k--){
int op, x;
cin >> op;
switch (op){
case -1:
++layer;
break;
case -2:
while (b[layer].top() != 0){
a[b[layer].top()].pop();
b[layer].pop();
}
--layer;
break;
case 0:
cin >> x;
cout << a[x].top() << '\n';
break;
default:
cin >> x;
if (a[op].topLayer() == layer)
a[op].resetTop(x);
else{
a[op].push(x, layer);
b[layer].push(op, 0);
}
break;
}
}
return 0;
}
``````