Advertisement
Jvsierra

ex cartas

Jan 20th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #define TF 50
  4.  
  5. void Empilha(int Pilha[TF], int &TL, int N)
  6. {
  7. Pilha[TL++] = N;
  8. }
  9.  
  10. int Desempilha(int Pilha[TF], int &TL)
  11. {
  12. return Pilha[--TL];
  13. }
  14.  
  15. int OlhaP(int Pilha[TF], int &TL)
  16. {
  17. return Pilha[TL - 1];
  18. }
  19.  
  20. void Insere(int Lista[TF], int &TL, int N)
  21. {
  22. Lista[TL++] = N;
  23. }
  24.  
  25. int Remove(int Lista[TF], int &TL)
  26. {
  27. int i, n;
  28.  
  29. n = Lista[0];
  30.  
  31. for(i = 0; i < TL - 1; i++)
  32. Lista[i] = Lista[i + 1];
  33.  
  34. TL--;
  35. return n;
  36. }
  37.  
  38. int main(void)
  39. {
  40. int n, i, Cartas[TF], Desc[TF], Aux[TF];
  41. int TLC, TLD, TLA;
  42.  
  43. scanf("%d", &n);
  44.  
  45. while(n > 0)
  46. {
  47. TLC = 0; TLD = 0; TLA = 0;
  48.  
  49. for(i = n; i >= 1; i--)
  50. Empilha(Cartas, TLC, i);
  51.  
  52. while(TLC > 1)
  53. {
  54. Insere(Desc, TLD, Desempilha(Cartas, TLC));
  55.  
  56. while(TLC > 0)
  57. Insere(Aux, TLA, Desempilha(Cartas, TLC));
  58.  
  59.  
  60. }
  61.  
  62. printf("Remaining card: %d\n", OlhaP(Cartas, TLC));
  63.  
  64. scanf("%d", &n);
  65. }
  66.  
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement