#C14419. Balance Parentheses
Balance Parentheses
Balance Parentheses
You are given a string representing a mathematical expression which may include letters, digits, operators, and parentheses. Your task is to identify all the unbalanced parentheses in the expression. The output should be the list of indices (0-indexed) of the characters that are unbalanced.
An opening parenthesis (')
is considered unbalanced if it does not have a matching closing parenthesis, and a closing parenthesis ')'
is unbalanced if it does not have a matching opening parenthesis.
For example:
- Input:
(a+b))
produces Output:5
because the character at index 5 is an unmatched closing parenthesis. - Input:
)a+b(
produces Output:0 4
(indices 0 and 4 are the unmatched ones).
Your program should read the expression from standard input and output the indices of unbalanced parentheses to standard output (separated by a single space). If there are no unbalanced parentheses, output an empty line.
inputFormat
The input consists of a single line containing the expression. The expression may contain spaces and other characters.
Input is provided from standard input (stdin).
outputFormat
Output the indices of the unbalanced parentheses separated by a single space. If there are no unbalanced parentheses, output an empty line. Output is to be printed to standard output (stdout).
## sample