Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct tipoElemento {
  5.  
  6. char teste;
  7. struct tipoElemento *proximo;
  8.  
  9. }Elemento;
  10.  
  11. typedef struct tipoPilha{
  12.  
  13. struct tipoElemento *topo;
  14.  
  15.  
  16. }Pilha;
  17.  
  18.  
  19. void init(Pilha *p){
  20.  
  21. p->topo=NULL;
  22.  
  23.  
  24. }
  25.  
  26. int push(Pilha *p, char valor){
  27.  
  28. Elemento *e = malloc(sizeof(Elemento));
  29. e->proximo=p->topo;
  30. e->teste=valor;
  31.  
  32. return 0;
  33. }
  34.  
  35. int pop(Pilha *p, char *valor){
  36.  
  37. if(p->topo == NULL){
  38. return 1;
  39. }
  40. else{
  41. Elemento *z;
  42. *valor = p->topo->teste;
  43. z = p->topo->proximo;
  44. p->topo = z;
  45.  
  46. return 0;
  47. }
  48. }
  49.  
  50.  
  51. int main(){
  52.  
  53. int n, i, x;
  54. char mina[1000];
  55.  
  56. // n vezes que vai entrar
  57. scanf("%d", &n);
  58.  
  59. for (i=0; i<n; i++){
  60.  
  61. //caracteres a ser alocados na pilha
  62. scanf("%s", mina);
  63. Pilha *p = malloc(sizeof(Pilha));
  64. init(p);
  65.  
  66. for (x=0; x<1000; x++){
  67. push(p, mina[x]);
  68. }
  69.  
  70. char *valor;
  71. int esq = 0;
  72. int dir = 0;
  73.  
  74. //essa porra ta em loop caralho
  75. while(pop(p, valor)){
  76.  
  77.  
  78. if(valor == '<'){
  79. esq++;
  80. }
  81. else if(valor == '>'){
  82. dir++;
  83. }
  84. }
  85.  
  86. if(dir >= esq){
  87. printf("%i",esq);
  88. }
  89. else{
  90. printf("%i",dir);
  91. }
  92. }
  93.  
  94.  
  95. return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement