DiYane

Balanced Brackets

Sep 19th, 2023
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. lines = int(input())
  2.  
  3. is_balanced = True
  4. has_open_bracket = False
  5.  
  6. for _ in range(0, lines):
  7.     line = input()
  8.     if line != '(' and line != ')':
  9.         continue
  10.        
  11.     is_open_bracket = line == '('
  12.     if has_open_bracket == is_open_bracket:
  13.         is_balanced = False
  14.         break
  15.        
  16.     has_open_bracket = is_open_bracket
  17.    
  18. if is_balanced:
  19.     print('BALANCED')
  20. else:
  21.     print('UNBALANCED')
Tags: python
Add Comment
Please, Sign In to add comment