Advertisement
Patey

Untitled

Apr 12th, 2021
795
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. #include<stdlib.h>
  2. #include<stdio.h>
  3. #include<string.h>
  4.  
  5. int st[100],vf = -1;
  6. char a[1];
  7.  
  8. int empty()
  9. {
  10.     if (vf == -1)
  11.         return 1;
  12.     else
  13.         return 0;
  14. }
  15.  
  16. void push()
  17. {
  18.     vf++;
  19.     st[vf] = a[0];
  20. }
  21.  
  22. void pop()
  23. {
  24.     vf--;
  25. }
  26.  
  27. int main()
  28. {
  29.     int i,nr=0;
  30.     int ok = 1;
  31.     while (1)
  32.     {
  33.         scanf("%c", a);
  34.         /*do{
  35.             ok = 1;
  36.             scanf("%c", a);
  37.             if ((strcmp(a, "F") != 0 && strcmp(a, "G") != 0) && strcmp(a, "S") != 0)
  38.             {
  39.                 printf("Nu ii bine\n");
  40.                 ok = 0;
  41.             }
  42.             scanf("%c", a);
  43.         } while (ok==0);*/
  44.         if (strcmp(a,"S")==0)
  45.             break;
  46.         if (empty() == 1)
  47.             push();
  48.         else if (a[0] != st[vf])
  49.         {
  50.             pop();
  51.             nr++;
  52.         }
  53.         else
  54.             push();
  55.         scanf("%c",a);
  56.     }
  57.  
  58.     printf("\n\nContinutul stivei este:\n");
  59.     for (i = 0; i <= vf; i++)
  60.     {
  61.         printf("%c\n", st[i]);
  62.     }
  63.     printf("\nNumarul de evaporari este: %d", nr);
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement