-
Notifications
You must be signed in to change notification settings - Fork 3
/
1069.c
65 lines (53 loc) · 1.01 KB
/
1069.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
//1069 - Diamantes e Areia
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
struct Diamt { char diamante;
struct Diamt *prox;
};
typedef struct Diamt TDiamt;
struct descrPilha { TDiamt *topo;};
typedef struct descrPilha DPilha;
int main()
{
char linha[1010] = "";
DPilha descritor;
TDiamt *aux, *aux2;
int N = 0, Dqtd =0, c = 0, d=0;
scanf("%d", &N);
while(c < N)
{
scanf("%s", linha);
descritor.topo = NULL;
d = 0;
Dqtd = 0;
while(d < strlen(linha))
{
if(linha[d] == '<')
{
aux = (TDiamt *) malloc(sizeof(TDiamt));
if(aux == NULL)
break;
aux->diamante = linha[d];
aux->prox = descritor.topo;
descritor.topo = aux;
}
else if(linha[d] == '>')
{
if(descritor.topo != NULL)
{
aux2 = descritor.topo;
descritor.topo = aux2->prox;
free(aux2);
Dqtd++;
}
}
d++;
}
printf("%d\n", Dqtd);
c++;
}
return 0;
}