Advertisement
bl00dt3ars

04. Balanced Brackets

May 27th, 2021
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. iterations = int(input())
  2.  
  3. opening_brackets = 0
  4. closing_brackets = 0
  5.  
  6. for i in range(iterations):
  7.     line = input()
  8.     if line == "(":
  9.         opening_brackets += 1
  10.     elif line == ")":
  11.         closing_brackets += 1
  12.     if closing_brackets > opening_brackets:
  13.         break
  14.     if opening_brackets - closing_brackets > 1:
  15.         break
  16.  
  17. if opening_brackets != closing_brackets:
  18.     print("UNBALANCED")
  19. else:
  20.     print("BALANCED")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement