fork download
  1. # 4949
  2. while True:
  3. sentence = str(input())
  4. stack = []
  5. if sentence == '.':
  6. print('yes')
  7. break
  8. else:
  9. for i in sentence:
  10. if i == '[' or '(':
  11. stack.append(i)
  12. elif i == ']':
  13. if stack[-1] == '[':
  14. stack.pop()
  15. else:
  16. print('no')
  17. break
  18. elif i == ')':
  19. if stack[-1] == '(':
  20. stack.pop()
  21. else:
  22. print('no')
  23. break
  24. else:
  25. if not stack: #break되지 않고 스택이 비어있는 상황
  26. print('yes')
  27. else:
  28. print('no')
Success #stdin #stdout 0.03s 9704KB
stdin
So when I die (the [first] I will see in (heaven) is a score list).
[ first in ] ( first out ).
Half Moon tonight (At least it is better than no Moon at all].
A rope may form )( a trail in a maze.
Help( I[m being held prisoner in a fortune cookie factory)].
([ (([( [ ] ) ( ) (( ))] )) ]).
 .
.
stdout
no
no
no
no
no
no
no
yes