Bracket Matching by

def f(s,b):
    m={'':'','(':')','[':']','{':'}','<':'>'}
    if not s:
        if len(b)>1: return "failed at: EOL"
        return "yes"
    i=s[0]
    if i in m: b.append(i)    
    elif m[b[-1]]!=i: return "failed at: "+s
    else: b.pop()
    return f(s[1:],b)
while 1:print f(raw_input(),[''])

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page