|
|
back to boardWho can help me with WA#3 ? #include <stdio.h> #define MaxN 100000+252 #define MaxPop MaxN/2+1 struct pointer { int s; char o; }; struct pointer GetPointer(int i) { struct pointer p; p.s=i/250; p.o=i % 250; return p;
} struct Stack { int V; struct pointer pred; }; int GetAdress(struct pointer p) { return p.s*250+p.o; } int A[1001]; int MP; struct Stack B[MaxN]; int Pop(int S) { int E; E=B[A[S]].V; A[S]=GetAdress(B[A[S]].pred); return E; } int Push(int S, int E) { int i=A[S]; MP++; B[MP].V=E; B[MP].pred=GetPointer(i); A[S]=MP; return 0; } int main() {
int N,i,j,E,k; int S; char command[10]; scanf("%d",&N);
MP=0; B[MP].V=0; B[MP].pred=GetPointer(0); for (i=1;i<1000;i++) A[i]=0; k=0; for (i=1;i<=N;i++) {
scanf("%s",command); if (command[1] == 'U'){ scanf("%d %d",&S,&E); Push(S,E); } else { scanf("%d",&S); k++; printf("%d\n",Pop(S)); } }
return 0; } |
|
|