Parenthesis X85651


Statement
 

pdf   zip

html

Write a program that reads a sequence of lines, and for each line prints the number of clean parenthesized regions it contains.

A clean parenthesized region is a segment of the string that is immediatly after an open parenthesis, is immediately followed by a closed parenthesis, and contains no open or closed parenthesis.

For instance the substring  "heha"  is a clean parenthesized region in the string:  "hello (heha) he said"
While in the string  "hello (he(ha))) he said"  the only clean parenthesized region corresponds to the substring  "ha"  since any larger parenthesized region contains other parenthesis.

Input

The input is a sequence of strings, each in one line.

Output

The output must contain, for each input line with at least one clean parenthesized region, the number of such regions in the line. Follow the format of the examples.

Public test cases
  • Input

    hello (heha) he said.
    hello (he(ha))) he said.
    

    Output

    Line 1 contains 1 regions.
    Line 2 contains 1 regions.
    
  • Input

    he (ooh (blabla (ky)) ... (sure?)))((
    ))))don't((
    ))(in fact)(do)))
    what about this one...

    Output

    Line 1 contains 2 regions.
    Line 3 contains 2 regions.
    
  • Input

    hello (ha) (he) () uhm
    ((()not cool()) 

    Output

    Line 1 contains 3 regions.
    Line 2 contains 2 regions.
    
  • Input

    aaaaaaa
    aaaaaaaaaa
    bf

    Output

    
            
                                
  • Information
    Author
    ProAl professors
    Language
    English
    Official solutions
    Python
    User solutions
    Python