#K53052. Balanced Parentheses Checker
Balanced Parentheses Checker
Balanced Parentheses Checker
You are given a string containing only the characters '(', ')', '{', '}', '[' and ']'. Your task is to determine if the given string has balanced parentheses. A string is said to be balanced if:
- Every opening bracket has a corresponding closing bracket of the same type.
- The pairs of brackets are properly nested.
In other words, if we denote an opening bracket as $x$ and its corresponding closing bracket as $y$, then the string is valid if every occurrence of $x$ is eventually closed by a matching $y$ in the correct order. For instance, the string (\{[]\})
is balanced while ([)]
is not.
Your program should read the input string from stdin
and write the output (either 1 for balanced or 0 for unbalanced) to stdout
.
inputFormat
The input consists of a single line containing a string s which may include the characters ( ) { } [ ]
. The string can be empty or contain up to 104 characters.
Input is provided via stdin
.
outputFormat
Output a single integer: print 1
if the string is balanced, or 0
otherwise. The result should be printed to stdout
.
({[]})
1