File tree Expand file tree Collapse file tree 3 files changed +65
-0
lines changed
Expand file tree Collapse file tree 3 files changed +65
-0
lines changed Original file line number Diff line number Diff line change 1+ a = int (input ())
2+
3+ for i in range (a ):
4+ res = []
5+ b = str (input ())
6+ for c in b :
7+ if c == '(' :
8+ res .append (c )
9+ elif c == ')' :
10+ if res :
11+ res .pop ()
12+ else :
13+ print ("NO" )
14+ break
15+ else :
16+ if len (res ) == 0 :
17+ print ("YES" )
18+ else :
19+ print ("NO" )
Original file line number Diff line number Diff line change 1+ while True :
2+ a = input ()
3+
4+ if a == '.' :
5+ break
6+ stk = []
7+ ans = True
8+
9+ for g in a :
10+ if g == '(' or g == '[' :
11+ stk .append (g )
12+ elif g == ')' :
13+ if len (stk ) == 0 :
14+ ans = False
15+ break
16+ if stk [- 1 ] == '(' :
17+ stk .pop ()
18+ else :
19+ ans = False
20+ break
21+ elif g == ']' :
22+ if len (stk ) == 0 :
23+ ans = False
24+ break
25+ if stk [- 1 ] == '[' :
26+ stk .pop ()
27+ else :
28+ ans = False
29+ break
30+
31+
32+ if ans and not stk :
33+ print ("yes" )
34+ else :
35+ print ("no" )
Original file line number Diff line number Diff line change 1+ num = int (input ())
2+ a = []
3+
4+ for i in range (num ):
5+ b = int (input ())
6+
7+ if b == 0 :
8+ a .pop ()
9+ else :
10+ a .append (b )
11+ print (sum (a ))
You can’t perform that action at this time.
0 commit comments