Advertisement
Bad_Programist

Untitled

Jan 27th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1. A = input()
  2. Check = []
  3. res = 'YES'
  4. for i in A:
  5.     if (i == '[' or i == '(' or i == '{'):
  6.         Check.append(i)
  7.     elif i == ']' and len(Check) > 0 and Check[-1] == '[':
  8.         Check.pop()
  9.     elif i == ')' and len(Check) > 0 and Check[-1] == '(':
  10.         Check.pop()
  11.     elif i == '}' and len(Check) > 0 and Check[-1] == '{':
  12.         Check.pop()
  13.     else:
  14.         res = 'NO'
  15.         break
  16. if len(Check) != 0:
  17.     res = 'NO'
  18. print(res)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement