Print bracket number
Given an expression exp of length n consisting of some brackets. The task is to print the bracket numbers when the expression is being parsed.
Input expression: (a+b)/(c+d) Output: 1 1 2 2 Input expression: ((()()(()))) Output: 1 2 3 3 4 4 5 6 6 5 2 1
So we actually need to parse the entire expression and whenever we are receiving an opening bracket we need to memorize its occurrence. So, we need a stack actually.
String s – which is to be parsed
Example with explanation: