#K79282. Well-Formed Parentheses Checker
Well-Formed Parentheses Checker
Well-Formed Parentheses Checker
You are given a string s
consisting solely of the characters ('
and ')'
. Your task is to determine whether the string is well-formed.
A string is considered well-formed if and only if:
- For every prefix of the string, the number of
('
is greater than or equal to the number of')
. - The total number of
('
equals the total number of')
, i.e., $$ \#('(') = \#(')') $$.
For example, the string "()()" is well-formed while "(()" is not.
inputFormat
The input is read from stdin as a single line that contains the bracket sequence.
Constraints: The input string consists only of the characters '(' and ')'.
outputFormat
Print to stdout a single line: True
if the sequence is well-formed, otherwise False
.
()
True