simeonshopov

Balanced brackets

Nov 27th, 2019
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. n = int(input())
  2. found_open = False
  3. balanced = True
  4.  
  5. for i in range(n):
  6.   symbol_ = input()
  7.   if symbol_ == '(':
  8.     if not found_open:
  9.       found_open = True
  10.     else:
  11.       balanced = False
  12.   if symbol_ == ')':
  13.     if found_open:
  14.       found_open = False
  15.     else:
  16.       balanced =  False
  17.  
  18.  
  19. if not found_open and balanced:
  20.   print('BALANCED')
  21. else:
  22.   print('UNBALANCED')
Advertisement
Add Comment
Please, Sign In to add comment