-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path1110.c
76 lines (62 loc) · 1.35 KB
/
1110.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//1110 - Jogando Cartas Fora
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
struct Cartas { char carta;
struct Cartas *prox;
};
typedef struct Cartas TCartas;
struct descrPilha { TCartas *topo, *final;
int qtd;
};
typedef struct descrPilha DPilha;
int main()
{
int vDescart[55], Cqtd, c=0, k=0;
DPilha descritor;
TCartas *aux;
while (scanf("%d", &Cqtd) && Cqtd != 0)
{
for(c=0; c < 55; c++)
vDescart[c] = 0;
k = 0;
descritor.topo = NULL;
descritor.qtd = 0;
for(c=Cqtd; c > 0; c--)
{
aux = (TCartas *) malloc(sizeof(TCartas));
if(aux == NULL)
break;
aux->carta = c;
aux->prox = descritor.topo;
descritor.topo = aux;
descritor.qtd++;
if(c == Cqtd)
descritor.final = aux;
}
while (descritor.qtd >= 2)
{
aux = descritor.topo;
descritor.topo = aux->prox;
vDescart[k] = aux->carta;
free(aux);
descritor.qtd--;
k++;
aux = descritor.topo->prox;
descritor.final->prox = descritor.topo;
descritor.final = descritor.topo;
descritor.topo = aux;
}
printf("Discarded cards:");
for(c=0; c < k; c++)
{
printf(" %d", vDescart[c]);
if(c != k-1)
printf(",");
}
printf("\nRemaining card: %d\n", descritor.final->carta);
}
return 0;
}