#K66677. Parentheses Checker
Parentheses Checker
Parentheses Checker
In this problem, you are given ( T ) expressions, and for each expression you must determine whether the parentheses are well-formed and properly nested. An expression is considered well-formed if every opening parenthesis ( ( ) has a corresponding closing parenthesis ( ) ) and the pairs are correctly ordered.
For example, the expression (a+(bc)-d)
is well-formed, while (a</em>(b+c)
is not. Use a stack-based approach or any other method to solve this problem efficiently.
inputFormat
The input begins with a single integer ( T ) representing the number of expressions. Following this, there are ( T ) lines, each containing a single expression. The expressions may contain letters, digits, arithmetic operators, spaces, and parentheses.
outputFormat
For each expression, output a single line containing either "YES" if the expression's parentheses are balanced and well-formed, or "NO" otherwise.## sample
3
(a+(b*c)-d)
((a+b)*(c-d))
(a*(b+c))
YES
YES
YES
</p>