Advertisement
viligen

balanced_brackets

Sep 30th, 2021
701
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. lines = int(input())
  2.  
  3. opening_brckt = 0
  4. closing_brckt = 0
  5.  
  6. for i in range(lines):
  7.     symbol = input()
  8.     if symbol == "(":
  9.         opening_brckt += 1
  10.  
  11.     elif symbol == ")":
  12.         closing_brckt += 1
  13.  
  14.     if opening_brckt - closing_brckt == 2:
  15.         break
  16.  
  17. if opening_brckt == closing_brckt and opening_brckt != 0:
  18.     print("BALANCED")
  19. else:
  20.     print("UNBALANCED")
  21.  
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement