fork download
  1. import sys
  2. input = sys.stdin.readline
  3.  
  4. ret = []
  5. for s in sys.stdin:
  6. if s == '.':
  7. break
  8.  
  9. st = []
  10. r = ''
  11. for c in s:
  12. if c in ['(', '[']:
  13. st.append(c)
  14. elif c == ')':
  15. if len(st) > 0 and st.pop() == '(':
  16. pass
  17. else:
  18. r = 'no'
  19. break
  20. elif c == ']':
  21. if len(st) > 0 and st.pop() == '[':
  22. pass
  23. else:
  24. r = 'no'
  25. break
  26.  
  27. if not r:
  28. if len(st) == 0:
  29. r = 'yes'
  30. else:
  31. r = 'no'
  32.  
  33. ret.append(r)
  34.  
  35. print(*ret, sep='\n')
Success #stdin #stdout 0.04s 9744KB
stdin
)).
.
stdout
no
yes