Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define TF 50
- void Empilha(int Pilha[TF], int &TL, int N)
- {
- Pilha[TL++] = N;
- }
- int Desempilha(int Pilha[TF], int &TL)
- {
- return Pilha[--TL];
- }
- int OlhaP(int Pilha[TF], int &TL)
- {
- return Pilha[TL - 1];
- }
- void Insere(int Lista[TF], int &TL, int N)
- {
- Lista[TL++] = N;
- }
- int Remove(int Lista[TF], int &TL)
- {
- int i, n;
- n = Lista[0];
- for(i = 0; i < TL - 1; i++)
- Lista[i] = Lista[i + 1];
- TL--;
- return n;
- }
- int main(void)
- {
- int n, i, Cartas[TF], Desc[TF], Aux[TF];
- int TLC, TLD, TLA;
- scanf("%d", &n);
- while(n > 0)
- {
- TLC = 0; TLD = 0; TLA = 0;
- for(i = n; i >= 1; i--)
- Empilha(Cartas, TLC, i);
- while(TLC > 1)
- {
- Insere(Desc, TLD, Desempilha(Cartas, TLC));
- while(TLC > 0)
- Insere(Aux, TLA, Desempilha(Cartas, TLC));
- }
- printf("Remaining card: %d\n", OlhaP(Cartas, TLC));
- scanf("%d", &n);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement