fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5.  
  6. void push(int *stack, int pointer, int value) {
  7. pointer--;
  8. stack[pointer] = value;
  9. printf(" %d %d ", pointer, stack[pointer]);
  10. }
  11.  
  12. int pop(int *stack, int pointer) {
  13. int temp;
  14. printf(" %d %d ", pointer, stack[pointer]);
  15. temp = stack[pointer];
  16. stack[pointer] = 0;
  17. pointer++;
  18. printf(" %d %d ", pointer, stack[pointer]);
  19. return temp;
  20. }
  21.  
  22. int main() {
  23. int *stack = (int*) malloc(sizeof(int) * 3000);
  24. static int pointer = 1500;
  25. int *charray = (int*) malloc(sizeof(int) * 3);
  26. int c;
  27. int i;
  28. while((c = getchar()) != '\n') {
  29. if(c == 'u')
  30. push(stack, pointer, getchar());
  31. else if(c == 'o')
  32. printf("%d ", pop(stack, pointer));
  33. else if(c == 'p')
  34. while((c = getchar()) != '"')
  35. putchar(c);
  36. else
  37. return 1;
  38. }
  39. free(stack);
  40. free(charray);
  41. return 0;
  42. }
  43.  
Success #stdin #stdout 0s 2304KB
stdin
u4u8oo
stdout
  1499 52    1499 56    1500 0    1501 0  0   1500 0    1501 0  0