-
Notifications
You must be signed in to change notification settings - Fork 3
/
1068.c
74 lines (60 loc) · 1.03 KB
/
1068.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
//1068 - Balanço de Parênteses I
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
struct exp { char par;
struct exp *prox;
};
typedef struct exp Texp;
struct descrPilha { Texp *topo;
int qtd;
};
typedef struct descrPilha DPilha;
int main()
{
char exp[3000] = "";
int c, sai;
DPilha d;
Texp *aux;
while (scanf("%s", exp) != EOF)
{
d.topo = NULL;
d.qtd = c = sai = 0;
do
{
if(exp[c] == '(')
{
aux = (Texp *) malloc(sizeof(Texp));
if(aux == NULL)
break;
aux->par = exp[c];
aux->prox = d.topo;
d.topo = aux;
d.qtd++;
}
if(exp[c] == ')')
{
if(d.topo == NULL)
{
sai = 1;
break;
}
else
{
aux = d.topo;
d.topo = aux->prox;
free(aux);
d.qtd--;
}
}
c++;
} while (c < strlen(exp));
if ((sai ==1) || d.qtd != 0)
printf("incorrect\n");
else
printf("correct\n");
}
return 0;
}