1013: Checking the brackets
[Creator : ]
Description
We would like to check if a given math string with brackets a valid
expression! The math expression only with integers and the following brackets:
[], (), and {}. For example:
{3+4*[2-(7+8)]}
this is a valid expression! In our problem, this is valid as well:
(3+4*[2-(7+8)])
that is: we only care if brackets match each other or not. For example, the following
is invalid:
(3+4*[2-(7+8)]}
(3+4*[2-(7+8)])*(9+10
(3+4*[2-(7+8)]])*(9+10
Please write a program to check if the given expression valid or not
ex
[], (), and {}. For example:
{3+4*[2-(7+8)]}
this is a valid ex
(3+4*[2-(7+8)])
that is: we only care if brackets match each other or not. For example, the following
is invalid:
(3+4*[2-(7+8)]}
(3+4*[2-(7+8)])*(9+10
(3+4*[2-(7+8)]])*(9+10
Please write a program to check if the given ex
Input
the first line contains integer N
In the next N lines, each line contains one expression!
In the next N lines, each line contains one ex
Output
For each expression, output VALID or INVALID, one line for each expression!
Sample Input Copy
5
({3+4}([4+5]))
({3+4}([4+5]))
({3+4}([4+5]))({3+4}([4+5]))({3+4}([4+5])){
({3+4}([4+5]]))({3+4}([4+5]))
({3+4}([4+5]))({3+4}([4+5])]
Sample Output Copy
VALID
VALID
INVALID
INVALID
INVALID