Advertisement
vasil_k_k

04. Balanced Brackets

Nov 19th, 2022 (edited)
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. number_of_lines = int(input())
  2. brackets = ""
  3. balance = ""
  4.  
  5. for _ in range(number_of_lines):
  6.     symbol = input()
  7.     for i in range(len(symbol)):
  8.         if symbol[i] == "(":
  9.             brackets += "("
  10.             balance += "open"
  11.         if symbol[i] == ")":
  12.             brackets += ")"
  13.             balance += "close"
  14.         if len(balance) == 9:
  15.             balance = ""
  16.  
  17. if brackets[0] == "(" and brackets[-1] == ")" and len(balance) == 0:
  18.     print("BALANCED")
  19. else:
  20.     print("UNBALANCED")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement