Maximum parenthesis nesting depth EASY Expresii (BAC) 10 XP 0 solved
Mobile coding works. A laptop is faster for long sessions.

Problem

The program reads from standard input a line containing an expression. Only round parentheses `(` and `)` are of interest; all other characters are ignored. The depth of a parenthesis is the number of open parentheses that contain it, including itself. Print the maximum depth reached in the expression. It is guaranteed that the parentheses are correctly matched (every `(` has a matching `)` and no `)` appears before its corresponding open parenthesis).

Input format

Input input.txt

The program reads from standard input a single line with the expression (at most 1000 characters long).

Output format

Output output.txt

The program prints to standard output a single non-negative integer: the maximum nesting depth of the parentheses. If no parentheses appear in the expression, print `0`.

Example

input
((a+b)*(c-(d+e)))
output
3

Ready to solve this challenge?

Create a free account to write code, submit solutions, and track your progress.

⌨️ Keyboard Shortcuts

Code Editor
Run Code
Ctrl Enter
Submit Code
Ctrl Shift Enter
Format Code
Shift Alt F
Toggle Comment
Ctrl /
Undo
Ctrl Z
Redo
Ctrl Y
Navigation
Global Search
/
Show Shortcuts
?
Close Modal
Esc

🔍 Interactive Debugger

0 / 0

Analyzing your code...

📦 Variables

No variables yet

📚 Call Stack
main() line 1
📤 Output
We use cookies

Essential cookies are always active. You can choose to enable preference and analytics cookies. Learn more