CompletingBrackets
SRM 280 · 2005-12-28 · by dimkadimon
Problem Statement
A series of brackets is complete if we can pair off each left bracket '[' with a right bracket ']' that occurs later in the series. Every bracket must participate in exactly one such pair.
Given a
Constraints
- text will have between 1 and 50 characters inclusive.
- text will contain only the characters '[' and ']'.
"[[" Returns: "[[]]"
Add two ']' to the end to make this complete.
"][" Returns: "[][]"
Add one to the beginning and one to the end.
"[[[[]]]]" Returns: "[[[[]]]]"
This is already complete.
"][][" Returns: "[][][]"
"[]" Returns: "[]"
"]]]]]]]]]]]]]]]]]]]]]]]]][[[[[[[[[[[[[[[[[[[[[[[[[" Returns: "[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]][[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]"
Long output
"[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]" Returns: "[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]"
long and complete
Submissions are judged against all 74 archived test cases, of which 7 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class CompletingBrackets with a public method string complete(string text) · 74 test cases · 2 s / 256 MB per case