Advertisement
Guest User

10graça

a guest
Aug 23rd, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string>
  5. using namespace std;
  6.  
  7. struct Expressao
  8. {
  9.     string operando;
  10.     Expressao *next;
  11. };
  12.  
  13. Expressao *topo;
  14.  
  15. //inicializa o ponteiro
  16. void ExpressaoConstrutor()
  17. {
  18.     topo = NULL;
  19. }
  20.  
  21. bool Empilhar(string novoValor)  //ESSA PORRA N TA PEGANDO PQQQQ PQPPP
  22. {
  23.     Expressao *NovaExpressao;
  24.  
  25.     NovaExpressao->operando = novoValor;
  26.     NovaExpressao->next = topo;
  27.  
  28.     topo = NovaExpressao;
  29.     return true;
  30. }
  31.  
  32. string Desempilhar()
  33. {
  34.     Expressao *temporaria;
  35.     temporaria = topo;
  36.  
  37.     string valor;
  38.     valor = topo -> operando;
  39.  
  40.     topo = topo -> next;
  41.  
  42.     temporaria->next = NULL; //medida de segurança
  43.     free(temporaria);
  44.  
  45.     return valor;
  46. }
  47.  
  48. void Limpar()
  49. {
  50.     Expressao *temporaria;
  51.  
  52.     while(topo != NULL)
  53.     {
  54.         temporaria = topo;
  55.         temporaria->next = NULL;
  56.  
  57.         topo = topo -> next;
  58.         free(temporaria);
  59.     }
  60. }
  61. //Responsável por montar a expressao
  62. void INF(char operador)
  63. {
  64.     string novaExpressao;
  65.  
  66.     if(operador == '^' || operador == 'v' || operador == '>')
  67.     {
  68.         string a = Desempilhar();
  69.         string b = Desempilhar();
  70.         string novaExpressao = "(" + b + operador + a + ")";
  71.         Empilhar(novaExpressao);
  72.     }
  73.     else  // -> NEGAÇAO
  74.     {
  75.         string a = Desempilhar();
  76.         string novaExpressao = "(" + operador + a + ")";
  77.         Empilhar(novaExpressao);
  78.     }
  79. };
  80.  
  81. //Responsavel por printar o resultado da expressao
  82. /*void VAL(char operador)
  83. {
  84. }
  85. */
  86. int main()
  87. {
  88.     string a;
  89.     a = "bla";
  90.     cout << Empilhar(a) << endl;
  91.     int qtd;
  92.     cin >> qtd;
  93.  
  94.     for(int i = 0; i < qtd; i++)
  95.     {
  96.         string act;
  97.         cin >> act;
  98.  
  99.         string exp;
  100.         cin >> exp;
  101.         for(int i = 0; i < exp.length(); i++)
  102.         {
  103.             if(exp[i] != '1' && exp[i] != '0')
  104.             {
  105.                 if(act[0]=='V')
  106.                     VAL(exp[i]);
  107.                 else
  108.                     INF(exp[i]);
  109.             }
  110.             else
  111.             {
  112.                 string aux = "";
  113.                 aux += exp[i];
  114.                 Empilhar(aux);
  115.             }
  116.         }
  117.     }
  118.     cout << topo->operando;
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement