Advertisement
GalinaKG

Balanced Brackets

May 29th, 2022
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1. number_of_lines = int(input())
  2. open_bracket = 0
  3. close_bracket = 0
  4.  
  5. for _ in range(number_of_lines):
  6.     string = input()
  7.     if string == "(":
  8.         open_bracket += 1
  9.         if open_bracket == 2 and close_bracket == 0:
  10.             print('UNBALANCED')
  11.             exit()
  12.     elif string == ")":
  13.         close_bracket += 1
  14.  
  15. if close_bracket > open_bracket or open_bracket > close_bracket:
  16.     print('UNBALANCED')
  17. else:
  18.     print('BALANCED')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement