Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- lines = len(input())
- is_balanced = False
- brackets = []
- for index in range(0, lines):
- symbol = input()
- if symbol.isalnum():
- symbol = input()
- if symbol == "(":
- brackets.append(symbol)
- elif symbol == ")":
- brackets.append(symbol)
- for index in range(len(brackets)):
- if brackets[index] == "(" and index % 2 == 0:
- is_balanced = True
- elif brackets[index] == ")" and index % 2 != 0 and is_balanced:
- is_balanced = True
- else:
- is_balanced = False
- break
- if is_balanced:
- print("BALANCED")
- else:
- print("UNBALANCED")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement