题解 | 好串
好串
https://www.nowcoder.com/practice/9b072237ebdd4dd99562f01cbf594fac
s = input()
def getresult(s):
stack = [] # 看字符a,b是否能完全配对
for c in s:
if c == 'a':
stack.append(c)
elif c == 'b':
if len(stack) > 0 and stack[-1] == 'a':
stack.pop()
else:
return 'Bad'
return 'Good' if len(stack) == 0 else 'Bad'
print(getresult(s))

查看45道真题和解析