Parentheses

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:

 ) []) (](] [)()] [(())) ()[][])( ([[]()](()

Input

The input consists of a series of words of between 1 and 1000
characters, one per line.

Output

For each given word, your program must print "correct" or "incorrect" as
required.

Scoring

- 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 ’]’.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T10:25:27.216Z

© Jutge.org, 2006–2026.
https://jutge.org
