wellBracketed3 X59845


Statement
 

pdf   zip   main.cc

html

Implementeu una funció RECURSIVA que, donat un string format sobre els caràcters d’obrir i tancar parèntesis, corchets i claudators (,),[,],{,}, comprobi si aquest string representa una seqüència ben parentitzada. Aquesta és la capcelera:

// Pre: s està format per parèntesis, corchets i claudators d'obrir i tancar (,),[,],{,}.
// Post: Retorna cert si i només si s representa una seqüència ben parentitzada.
bool wellBracketed3(string s);

Observació Només cal enviar el procediment demanat; el programa principal serà ignorat.

Sample session
wellBracketed3("[") = false
wellBracketed3("({}") = false
wellBracketed3("(") = false
wellBracketed3("{") = false
wellBracketed3("[{}") = false
wellBracketed3("]") = false
wellBracketed3("[]") = true
wellBracketed3("((({})[]()){})") = true
wellBracketed3("({})") = true
wellBracketed3("{[]}[") = false
wellBracketed3(")){}{}[]]") = false
wellBracketed3("}{}[]{(){}}(())") = false
wellBracketed3("{({}][]}([])[]") = false
wellBracketed3("{}{([][]){}}") = true
wellBracketed3("]()") = false
wellBracketed3("{}((){}())") = true
wellBracketed3("(())}([([])])[]") = false
wellBracketed3("())(({}))") = false
wellBracketed3("{}(]") = false
wellBracketed3("(]") = false
wellBracketed3("{()}{}[{}{}]") = true
wellBracketed3("()}[()](())") = false
wellBracketed3("[{)]") = false
wellBracketed3("{([])}(){[[") = false
wellBracketed3("{[[]]{}{}}") = true
wellBracketed3("()") = true
wellBracketed3("[[]]]") = false
wellBracketed3("}}](()([])())") = false
wellBracketed3("[][({()}){}])") = false
wellBracketed3("[{(]}{{}}()]()") = false
Information
Author
PRO1
Language
Catalan
Official solutions
Unknown. This problem is being checked.
User solutions
C++