Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4.  
  5. int stiva[100];
  6. int top = -1;
  7.  
  8. void Push(int elem) {
  9.     stiva[++top] = elem;
  10. }
  11.  
  12. int Pop() {
  13.     return stiva[top--];
  14. }
  15.  
  16. int main() {
  17.     int x = 0x0010;
  18.     int y = 0xFF00;
  19.  
  20.     char opt[10];
  21.     do {
  22.         fgets(opt, 10, stdin);
  23.         opt[strlen(opt) - 1] = '\0';
  24.        
  25.         if (strcmp(opt, "PUSH ^") == 0) {
  26.             Push(x ^ y);
  27.         }
  28.         else if (strcmp(opt, "PUSH &") == 0) {
  29.             Push(x & y);
  30.         }
  31.         else if (strcmp(opt, "PUSH |") == 0) {
  32.             Push(x | y);
  33.         }
  34.         else if (strcmp(opt, "POP") == 0) {
  35.             printf("%x\n", Pop());
  36.         }
  37.         else {
  38.             exit(1);
  39.         }
  40.     }while (1);
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement