Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n_lines = int(input())
- open_brack = None
- closed_brack = None
- is_balanced = None
- counter = 0
- for each_line in range(n_lines):
- command = input()
- if command != '(' and command != ')':
- pass
- else:
- if command == '(':
- counter += 1
- if open_brack is None:
- open_brack = command
- else:
- closed_brack = command
- elif command == ')':
- counter += 1
- if open_brack is None:
- open_brack = command
- else:
- closed_brack = command
- if counter == 2:
- if open_brack == '(' and closed_brack == ')':
- is_balanced = True
- else:
- is_balanced = False
- open_brack = None
- closed_brack = None
- counter = 0
- if is_balanced:
- print('BALANCED')
- else:
- print('UNBALANCED')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement