shiluomax @ 2022-10-26 21:33:05
#include<iostream>
using namespace std;
struct grid//格子
{
int k;//物品
int v;//编号
grid* last;//上一个
};
class chest//小柜子
{
grid* head;
grid* p;
public:
chest()
{
head= NULL;
p = head;
}
void open(int j,int k)//进栈
{
grid* newp = new grid;
newp->k = k;
newp->v = j;
newp->last = p;
p = newp;
}
int cheeks(int j)
{
grid* m;
m = this->p;
while (m!= NULL)
{
if (m->v == j)
{
return m->k;
}
m = m->last;
}
return 0;
}
};
class bigchest
{
chest a[10000];
public:
void in(int n)
{
int i, j, k;//i为小柜子编码 j为第j个格子,j为存放品
cin >> i >> j >> k;
if (i > n)
return;
else
a[i].open(j, k);
}
int cheek(int n)
{
int i,j,h=0;//i为小柜子编码 j为第j个格子
cin >> i >> j;
if(i>n)
return 0;
else
h = a[i].cheeks(j);
return h;
}
};
int main()
{
int n, q;//n小柜子数,q操作次数
int a[100],i=0,m=0;
cin >> n >> q;
bigchest s;
while (q > 0)
{
int l;
cin >> l;
if (l == 1)
{
s.in(n);
q--;
}
else if (l == 2)
{
a[i]=s.cheek(n);
q--;
i++;
m++;
}
}
for (i = 0; i < m; i++)
cout << a[i] << endl;
return 0;
}
by shiluomax @ 2022-10-26 21:34:09
全是RE
by zhangzhichu123456 @ 2022-10-26 21:36:29
建议把数组全部开到一百万
by BIG_CUTE_BUG @ 2022-10-26 21:37:10
可以试试把数组开大一点
by BIG_CUTE_BUG @ 2022-10-26 21:38:31
(
by Tx1234567 @ 2023-01-12 20:17:47
用vector