Your task is to write a program that determines, for each given word,
if it is correctly parenthesized or not. Here, a word is a non empty
sequence of ’(’, ’)’, ’[’ and
’]’ without intermediate spaces.
For instance, these are some words correctly parenthesized:
() [] ()[] [()] ((())) ()[]([]) ([[]()](()))
And these are some words incorrectly parenthesized:
) []) (](] [)()] [(())) ()[][])( ([[]()](()
The input consists of a series of words of between 1 and 1000 characters, one per line.
For each given word, your program must print "correct"
or "incorrect" as required.
TestA:
Some test cases will include words like the ones in the instance 1,
that is, only with the characters ’(’ y
’)’.
TestB:
Other test cases will include words with the characters
’(’, ’)’, ’[’ y
’]’.
Input
() ( ()() ((())) )( (())()))
Output
correct incorrect correct correct incorrect incorrect
Input
[] ()[] [()] ([[]()](())) []) ([[]()](()
Output
correct correct correct correct incorrect incorrect