Advertisement
tod36

05. Balanced Brackets

May 30th, 2020
943
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. lines_input = int(input())
  2. open_bracket = 0
  3. closed_bracket = 0
  4. flag = False
  5.  
  6. for i in range(1, lines_input + 1):
  7.     symbol_input = input()
  8.     if symbol_input == '(' and not flag:
  9.         open_bracket += 1
  10.         flag = True
  11.     elif symbol_input == ')' and flag:
  12.         closed_bracket += 1
  13.         flag = False
  14. if open_bracket == closed_bracket and open_bracket > 0:
  15.     print('BALANCED')
  16. else:
  17.     print('UNBALANCED')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement