Balanced parentheses with a stack EASY Liste stive cozi (BAC) 10 XP 0 solved
Mobile coding works. A laptop is faster for long sessions.

Problem

Read from standard input a string of at most `2000` characters that may contain round brackets `(` `)`, square brackets `[` `]`, curly braces `{` `}`, and any other characters (letters, digits, operators). We say the string has **balanced** brackets if: - every opening bracket has a matching closing bracket of the same type; - brackets close in the reverse order of opening (they do not intersect). Print `DA` if the brackets are balanced and `NU` otherwise. Use a **stack** implemented with a character array and an index `top`. Do not use STL containers.

Input format

Input input.txt

The program reads from standard input a single string on one line. - the string has at most `2000` characters; - characters that are not brackets are ignored during the check; - a string with no brackets at all is considered balanced.

Output format

Output output.txt

The program prints to standard output the word `DA` or `NU`, followed by a newline.

Example

input
(a+[b-{c*d}])
output
DA

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