Ejemplo n.º 1
0
void invertePilha(pilha *pilinv, pilha *pil)
{
    int i, j = pil->topo;
    inicPilha(pilinv);
    for(i=j; i >= 0; i--)
    {
        push(pilinv, pil->vet[i]);
        pop(pil);
    }
    printf("Pilha Invertida:\n");
    imprimePilha(pilinv);
}
Ejemplo n.º 2
0
Archivo: 1944.c Proyecto: Gruutak/uri
int main(){
	int n, i, j, cont = 0, aux;
	Pilha *s = malloc(sizeof(Pilha));
	char v[] = { 'F', 'A', 'C', 'E' }, v2[4];

	inicPilha(s);

	for(i = 0; i < 4; i++)
		empilha(s, v[i]);

	scanf("%d", &n);
	getchar();

	for(i = 0; i < n; i++){
		scanf("%c %c %c %c", &v[0], &v[1], &v[2], &v[3]);
		getchar();
		for(j = 0; j < 4; j++){
			v2[j] = desempilha(s);
		}

		aux = 0;

		for(j = 0; j < 4; j++){
			if(v[j] == v2[j]);
				aux++;
		}

		if(aux == 4){
			cont++;

			for(j = 0; j < 4; j++){
				empilha(s, v2[j]);
			}
		}
		else{
			for(j = 0; j < 4; j++){
				empilha(s, v[j]);
			}
		}
	}

	printf("%d\n", cont);

	return 0;
}
Ejemplo n.º 3
0
int main(){
	Pilha s;
	char aux;
	//char inf[] = "(a-b)/(c+d)*e";
	char inf[] = "A^B*C-D+E/F/(G-H)";
	int i = 0;
		
	inicPilha(&s);
	for(i = 0; i < strlen(inf); i++) {
		//printf("%c", inf[i]);
		switch(inf[i]) {
			case '(': push(&s, inf[i]); break;
			case '*':
			case '+':
			case '/':
			case '-':
			case '^':
				while(!PilhaVazia(&s) && verificaPrec(elemTopo(&s), inf[i]) &&
						elemTopo(&s) != '(')
					printf("%c", pop(&s));
				push(&s, inf[i]);
				break;
			case ')': 
				aux = pop(&s);
				while(aux != '('){
					printf("%c", aux);
					aux = pop(&s);
				}
				break;
			default: printf("%c", inf[i]);
				break;
		}
		
	}
	while(!PilhaVazia(&s))
		printf("%c", pop(&s));
		

	printf("\n");

	return 0;
}