Given an input string consisting of parentheses and spaces, decide
whether or not the parentheses match up correctly. For example,
"( () ( ))
" do match, but "( ) ) )
" don't.
Formally, a Balanced Term is a left parenthesis "(
", followed by a Balanced Expression,
followed by a right parenthesis ")
" and a Balanced Expression is a series
of zero or more Balanced Terms. Spaces are ignored in determining whether or
not an expression is balanced.
The first line of input will be an integer indicating how many test expressions follow. Then each test expression will be on a line by itself. Your program should output "Balanced" for each line consisting of a Balanced Expression and "Not Balanced" for the other lines.
Sample Input
5 ( () ( )) ( ) ) ) () ()( ) () ())(() (((()))Sample Output
Balanced Not Balanced Balanced Not Balanced Not Balanced