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
    admin  commented on Sept. 22, 2021, 10:39 a.m.

    Hint:

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

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

  • 0
    admin  commented on July 6, 2020, 6:29 p.m. edited

    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
    }