TopcoderArchiveVisit Topcoder
Archive7 Apr 2001
TCCC '01 Round 2

Syntax

Problem statement, definition, constraints, and public examples.

Problem Statement

Create a class called Syntax. Given a String that contains, among other
characters, parentheses '()', square brackets '[ ]' and curly
 braces '{}',
create a solution that will determine if the string is balanced.  The String is
considered balanced if all of the parentheses,
 brackets, and braces are
nested, opened, and closed properly.  The rules are as follows:

There must be equal numbers of beginning and ending delimiters for each type.
Any time a closing delimiter occurs, it must match the most recent unmatched
open delimiter.
An ending delimiter can never occur without a cooresponding begining delimiter
of the same type.

EXAMPLES:

x(y(z{test})abc)  - should return true
()                - should return true
([)]              - should return false
[[]](()){{{}}}    - should return true
abc(def(ghi)      - should return false

Here is the method signature:
boolean match(String input)

We will check to make sure the input is valid.

Definition

Class:
Syntax
Method:
match
Parameters:
String
Returns:
boolean
Method signature:
boolean match(String param0)
(be sure your method is public)

Constraints

    Examples

      No public sample cases were explicitly marked for this problem in the original data.

      Back to all problems