Advertisement
Guest User

parenteses.c

a guest
May 22nd, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include <stdio.h>
  2. #include "pilha.h"
  3.  
  4. int main() {
  5. int quantidade, posicao, nivel;
  6.  
  7. printf("Quantidade de caracteres:\n");
  8. scanf("%d", &quantidade);
  9.  
  10. char frase[quantidade];
  11. printf("Frase:\n");
  12. scanf("%s", frase);
  13.  
  14. printf("Verificar caracter na posicao?\n");
  15. scanf("%d", &posicao);
  16. char procurado = frase[posicao - 1];
  17.  
  18. int abortado = 0;
  19. Pilha *lisp = create();
  20.  
  21. for (int i = 0; i < quantidade; i++) {
  22. if (frase[i] == '(') {
  23. push(lisp, frase[i]);
  24. }
  25. if (frase[i] == ')') {
  26. if (isEmpty(lisp)) {
  27. abortado = 1;
  28. break;
  29. } else {
  30. pop(lisp);
  31. }
  32. }
  33. if (i == posicao - 1) {
  34. nivel = size(lisp);
  35. }
  36. }
  37. if (!abortado && isEmpty(lisp)) {
  38. printf("A lista esta balanceada! %c está no nivel %d", procurado, nivel);
  39. } else {
  40. printf("A lista nao esta balanceada");
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement