Parentheses P35352


Statement
 

pdf   zip

thehtml

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:  ‍30 Points ‍

    Some test cases will include words like the ones in the instance 1, that is, only with the characters ’(’ y ’)’.

  • TestB:  ‍70 Points ‍

    Other test cases will include words with the characters ’(’, ’)’, ’[’ y ’]’.

Public test cases
  • Input

    ()
    (
    ()()
    ((()))
    )(
    (())()))
    

    Output

    correct
    incorrect
    correct
    correct
    incorrect
    incorrect
    
  • Input

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

    Output

    correct
    correct
    correct
    correct
    incorrect
    incorrect
    
  • Information
    Author
    Omer Giménez
    Language
    English
    Translator
    Carlos Molina
    Original language
    Spanish
    Other languages
    Spanish
    Official solutions
    C++
    User solutions
    C++ Java