-
Notifications
You must be signed in to change notification settings - Fork 0
/
3.py
59 lines (48 loc) · 1.12 KB
/
3.py
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
def push(item):
global lengthS
lengthS +=1
stek[lengthS] = item
def delete():
global lengthS
a=stek[lengthS]
lengthS -=1
return a
f=open('brackets.in', 'r')
t=open('brackets.out','w')
lengthS = -1
stek = [0 for i in range(1000001)]
length=0
a=f.readline().split()
flag=1
while a:
a=a[0]
flag=1
length=0
for i in a:
if i=='(' or i=='[':
push(i)
length+=1
elif length!=0:
sim = delete()
length -= 1
if i==')':
if sim=='(':
flag=flag
else:
flag=0
break
elif i==']':
if sim=='[':
flag=flag
else:
flag=0
break
else:
flag=0
break
if flag and length==0:
print('YES', file=t)
else:
print('NO', file=t)
a=f.readline().split()
t.close()