nq1s788

Проверка на псп через стек

Feb 23rd, 2026
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.34 KB | None | 0 0
  1. s = input()
  2. st = []
  3. for e in s:
  4.     if e in '{[(':
  5.         st.append(e)
  6.     else:
  7.         if len(st) == 0:
  8.             print('NO')
  9.             exit(0)
  10.         if st[-1] + e in ['[]', '{}', '()']:
  11.             st.pop(-1)
  12.         else:
  13.             print('NO')
  14.             exit(0)
  15. if len(st) == 0:
  16.     print('YES')
  17. else:
  18.     print('NO')
Advertisement
Add Comment
Please, Sign In to add comment