#K95807. Balanced Parentheses Checker
Balanced Parentheses Checker
Balanced Parentheses Checker
The problem asks you to determine if a given string has balanced parentheses. Consider the three types of brackets: ()
, {}
, and []
. A string is considered balanced if each opening bracket has a corresponding closing bracket in the correct order. Note that characters other than these brackets can be present in the string and should be ignored.
Example:
- Input:
a*(b+c)-{d/e}
→ Output:Yes
- Input:
(a*[b-c]+{d/e}
→ Output:No
Your task is to write a program that reads an expression from standard input and outputs "Yes" if the parentheses are balanced, or "No" otherwise.
inputFormat
A single line containing a string expression
composed of letters, digits, spaces, and the characters ()
, {}
, and []
.
outputFormat
Print Yes
if the expression has balanced parentheses, otherwise print No
.
a*(b+c)-{d/e}
Yes