String practice 2


Submit solution

Points: 1
Time limit: 1.0s
Memory limit: 64M

Author:
Problem type
Allowed languages
C, C++, Python3

Brackets are used in many places, and in this task your job is to make sure the square brackets are syntactically correct. The rules are very simple, matching pairs of brackets are considered valid.

E.g. the following brackets are valid:

[] [ [ ] ]
[ []]

The following is invalid:

[] ]

Input Specification

Each line will contain a single test case. Each case will contain no more than 200 characters.

There will be multiple test cases, until EOF in the end.

Output Specification

The output should contain the same number of lines as input, each line either Yes or No, indicating whether the sequence is valid.

Sample Input

[] [ [ ] ]
[ []]
[] ]
][

Sample Output

Yes
Yes
No
No

Comments


  • 0
    jetic  commented on Sept. 22, 2021, 5:39 p.m.

    Hint:

    In Python, to keep reading from stdin until EOF, you can do this:

    while True:
        try :
            line = input()
            ...
        except EOFError:
            break

  • 0
    jetic  commented on July 7, 2020, 1:29 a.m.

    Hint:

    In C++, to keep reading in a complete line until EOF, you can do this:

    string line;
    while (getline(cin, line)) {
        // do your stuff
    }