Checking parenthesis P69643


Statement
 

pdf   zip

thehtml

Write a program that checks the correct parenthesization of several given words by using a stack of characters.

Input

Input consists of several non-empty words made up only of ‘(’, ‘)’, ‘[’ and ‘]’.

Output

For every word, tell if it is correct or not, following the format of the example.

Public test cases
  • Input

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

    Output

    ()[]() is correct
    [(]) is incorrect
    []( is incorrect
    ((()) is incorrect
    (([]()[()])) is correct
    
  • Input

    () [] (()) [
    

    Output

    () is correct
    [] is correct
    (()) is correct
    [ is incorrect
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++ Python
    User solutions
    C++ Python