Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct tipoElemento {
- char teste;
- struct tipoElemento *proximo;
- }Elemento;
- typedef struct tipoPilha{
- struct tipoElemento *topo;
- }Pilha;
- void init(Pilha *p){
- p->topo=NULL;
- }
- int push(Pilha *p, char valor){
- Elemento *e = malloc(sizeof(Elemento));
- e->proximo=p->topo;
- e->teste=valor;
- return 0;
- }
- int pop(Pilha *p, char *valor){
- if(p->topo == NULL){
- return 1;
- }
- else{
- Elemento *z;
- *valor = p->topo->teste;
- z = p->topo->proximo;
- p->topo = z;
- return 0;
- }
- }
- int main(){
- int n, i, x;
- char mina[1000];
- // n vezes que vai entrar
- scanf("%d", &n);
- for (i=0; i<n; i++){
- //caracteres a ser alocados na pilha
- scanf("%s", mina);
- Pilha *p = malloc(sizeof(Pilha));
- init(p);
- for (x=0; x<1000; x++){
- push(p, mina[x]);
- }
- char *valor;
- int esq = 0;
- int dir = 0;
- //essa porra ta em loop caralho
- while(pop(p, valor)){
- if(valor == '<'){
- esq++;
- }
- else if(valor == '>'){
- dir++;
- }
- }
- if(dir >= esq){
- printf("%i",esq);
- }
- else{
- printf("%i",dir);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement