Advertisement
GuiBrust

Untitled

Sep 21st, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.66 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <windows.h>
  4.  
  5. struct EST_PILHA{
  6.     int TOPO;
  7.     int INFO[1000];
  8. };
  9.  
  10. struct EST_PILHA Cria (void)
  11. {
  12.     struct EST_PILHA P;
  13.     P.TOPO = -1;
  14.     return P;
  15. }
  16.  
  17. int PilhaVazia(struct EST_PILHA P)
  18. {
  19.      //Retorna 1 se a pilha estiver vazia, caso contrário retorna 0;
  20.      if(P.TOPO == -1)
  21.         return 0;
  22.      else
  23.         return 1;
  24. }
  25.  
  26. int QuantidadePilha(struct EST_PILHA P)
  27. {
  28.     return P.TOPO + 1;
  29. }
  30.  
  31. void POP(struct EST_PILHA *P)
  32. {
  33.      int Valor = 0;
  34.      Valor = (*P).INFO [(*P).TOPO];
  35.      (*P).TOPO--;
  36. }
  37. struct EST_PILHA PUSH(int Vlr, struct EST_PILHA P)
  38. {    
  39.      
  40.         P.TOPO++;
  41.         P.INFO[P.TOPO] = Vlr;
  42.      
  43.      return P;
  44. }
  45.  
  46. void  iguala(EST_PILHA *P){
  47.  
  48.     if((*P).TOPO>-1){
  49.         while((*P).TOPO>-1){
  50.             int Valor = 0;
  51.             Valor = (*P).INFO [(*P).TOPO];
  52.             (*P).TOPO--;   
  53.         }
  54.     }
  55. }                                      
  56.  
  57.  
  58. int main(int argc, char** argv)
  59. {
  60.     char exp[1001];
  61.     int i,vlr;
  62.     struct EST_PILHA Pilha;  
  63.     bool boo=true;
  64.     Pilha = Cria();
  65.     while(scanf("%s",&exp) != EOF){
  66.         i=0;
  67.         vlr=1;
  68.         boo=true;
  69.         printf("%d", Pilha.TOPO);
  70.         iguala(&Pilha);
  71.         printf("%d", Pilha.TOPO);
  72.         if(Pilha.TOPO==-1){
  73.             while(exp[i]!='\0' && boo==true){  
  74.                       if(exp[i]=='('){
  75.                         vlr=1;
  76.                           Pilha=PUSH(vlr,Pilha);
  77.                       }
  78.                       else if(exp[i]==')')
  79.                       {
  80.                           POP(&Pilha);
  81.                           if(Pilha.TOPO==-2){
  82.                               boo=false;
  83.                               Pilha=PUSH(vlr,Pilha);
  84.                           }
  85.                       }
  86.                       i++; 
  87.             }
  88.         }
  89.         if(Pilha.TOPO==-1 && boo==true){
  90.             printf("correct\n");
  91.         }
  92.         else if(Pilha.TOPO!=-1){
  93.             printf("incorrect\n");
  94.             }
  95.        
  96.        
  97.     }
  98.    
  99.     return 0;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement