#include <stdio.h>
#include <stdlib.h>
#define TAM_PILHA 2
#define NUM_ENTRA 5
void empilha( int * pilha, int * topo, int valor)
{
if ( * topo <= TAM_PILHA)
{
pilha[ * topo] = valor;
( * topo) ++;
}
else
{
}
}
int desempilha( int * pilha, int * topo)
{
if ( * topo > 0 )
{
( * topo) --;
return pilha[ * topo] ;
}
else
{
}
}
int main( )
{
int pilha_par[ TAM_PILHA] , pilha_impar[ TAM_PILHA] , topo_par = 0 , topo_impar = 0 ;
int i = 0 , num_do_usuario = 0 ;
for ( i = 0 ; i < NUM_ENTRA; i++ )
{
printf ( "\n Entre com um numero: " ) ; scanf ( "%d" , & num_do_usuario
) ;
if ( ( num_do_usuario % 2 ) == 0 )
{
empilha( pilha_par, & topo_par, num_do_usuario) ;
}
else
{
empilha( pilha_impar, & topo_impar, num_do_usuario) ;
}
}
printf ( "\n \n Numeros pares sao: " ) ; while ( topo_par > 0 )
{
printf ( "%d " , desempilha
( pilha_par
, & topo_par
) ) ; }
printf ( "\n \n Numeros impares sao: " ) ; while ( topo_impar > 0 )
{
printf ( "%d " , desempilha
( pilha_impar
, & topo_impar
) ) ; }
return 0 ;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KIAojZGVmaW5lIFRBTV9QSUxIQSAyCiNkZWZpbmUgTlVNX0VOVFJBIDUKCnZvaWQgZW1waWxoYShpbnQgKnBpbGhhLCBpbnQgKnRvcG8sIGludCB2YWxvcikKewogICAgaWYgKCp0b3BvIDw9IFRBTV9QSUxIQSkKICAgIHsKICAgICAgICBwaWxoYVsqdG9wb10gPSB2YWxvcjsKICAgICAgICAoKnRvcG8pKys7CiAgICB9CiAgICBlbHNlCiAgICB7CiAgICAgICAgcHJpbnRmKCJQaWxoYSBDaGVpYVxuIik7CiAgICB9Cn0KCmludCBkZXNlbXBpbGhhKGludCAqcGlsaGEsIGludCAqdG9wbykKewogICAgaWYgKCp0b3BvID4gMCkKICAgIHsKICAgICAgICAoKnRvcG8pLS07CiAgICAgICAgcmV0dXJuIHBpbGhhWyp0b3BvXTsKICAgIH0KICAgIGVsc2UKICAgIHsKICAgICAgICBwcmludGYoIlBpbGhhIFZhemlhXG4iKTsKICAgIH0KfQoKaW50IG1haW4oKQp7CiAgICBpbnQgcGlsaGFfcGFyW1RBTV9QSUxIQV0sIHBpbGhhX2ltcGFyW1RBTV9QSUxIQV0sIHRvcG9fcGFyID0gMCwgdG9wb19pbXBhciA9IDA7CiAgICBpbnQgaSA9IDAsIG51bV9kb191c3VhcmlvID0gMDsKICAgIGZvciAoaSA9IDA7IGkgPCBOVU1fRU5UUkE7IGkrKykKICAgIHsKICAgICAgICBwcmludGYoIlxuRW50cmUgY29tIHVtIG51bWVybzogIik7CiAgICAgICAgc2NhbmYoIiVkIiwgJm51bV9kb191c3VhcmlvKTsKICAgIAogICAgICAgIGlmICgobnVtX2RvX3VzdWFyaW8gJSAyKSA9PSAwKQogICAgICAgIHsKICAgICAgICAgICAgZW1waWxoYShwaWxoYV9wYXIsICZ0b3BvX3BhciwgbnVtX2RvX3VzdWFyaW8pOwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICBlbXBpbGhhKHBpbGhhX2ltcGFyLCAmdG9wb19pbXBhciwgbnVtX2RvX3VzdWFyaW8pOwogICAgICAgIH0KICAgIAogICAgfQogICAgCiAgICBwcmludGYoIlxuXG5OdW1lcm9zIHBhcmVzIHNhbzogIik7CiAgICB3aGlsZSAodG9wb19wYXIgPiAwKQogICAgewogICAgICAgIHByaW50ZigiJWQgIiwgZGVzZW1waWxoYShwaWxoYV9wYXIsICZ0b3BvX3BhcikpOwogICAgfQogICAgCiAgICBwcmludGYoIlxuXG5OdW1lcm9zIGltcGFyZXMgc2FvOiAiKTsKICAgIHdoaWxlICh0b3BvX2ltcGFyID4gMCkKICAgIHsKICAgICAgICBwcmludGYoIiVkICIsIGRlc2VtcGlsaGEocGlsaGFfaW1wYXIsICZ0b3BvX2ltcGFyKSk7CiAgICB9CiAgICAKICAgIHByaW50ZigiXG5cbiIpOwogICAgCiAgICAKICAgIHJldHVybiAwOwp9