summaryrefslogtreecommitdiff
path: root/python/parentesi.py
blob: e4967a9125ceee5ed3c11b1cf6279617efdb6b5e (plain)
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
stringa = []

with open('input.txt', 'r') as fin:
    linea = fin.readline()

    for i in linea:
        if i is not ' ':
            stringa.append(i)


t = q = g = 0
tot = 0


for i in stringa:
    if i == '(':
        t += 1
    elif i == '[':
        q += 1
    elif i == '{':
        g += 1

    if i == ')' and t > 0:
        t -= 1
        tot += 1
    elif i == ']' and q > 0:
        q -= 1
        tot += 1
    elif i == '}' and g > 0:
        g -= 1
        tot += 1


with open('output.txt', 'w') as fout:
    fout.write(str(tot))