TOPIC

Heelp10 pf

k16bits asked 4 years ago

include

include

include

define max 1000

typedef struct{ char vetor[max]; int pos; }pilha;

pilha criar(){ pilha x = (pilha)malloc(sizeof(pilha)); x->pos = 0; return x; } int push(pilha x,char n){ x->vetor[x->pos++] = n; };

int pop(pilha* x, char n){ n = x->vetor[x->pos]; x->vetor[x->pos--] = n; }

void libera(pilha *x){ free(x); }

int cheia(pilha *x){ return(x->pos == max); }

int vazia(pilha *x){ return(x->pos == 0); }

int main(){ char entrada[max]; int i,N,diamantes = 0; pilha* x = criar(); scanf("%d",&N); while(N > 0){ diamantes = 0; scanf(" %[^\n]s",entrada); // reconhecer entradas int tam_str = strlen(entrada); for(i = 0; i < tam_str; i++){ if(entrada[i] == '<'){ push(x,entrada[i]);

    }else if(entrada[i] == '>'){
        if(!vazia(x)){
            pop(x,entrada[i]);
            diamantes+=1;
            }
        }
    }
printf("%d\n",diamantes);   
N--;
}

}

This topic has not been answered yet. Be the first!

Remember not post solutions. Your post may be reviewed by our moderators.