# -*- coding: utf-8 -*-
"""
Created on Sun Mar  8 17:03:43 2020

@author: BZL
"""
from pythonds.basic.stack import Stack

# 括号匹配算法
def test_str(str):
    str_stack = Stack()
    for str_one in str:
        if str_one in ['{' , '}' , '[' , ']' , '(' , ')']:
            if str_one in ['{', '[' , '(']:
                str_stack.push(str_one)
            else:
                if str_one == '}':
                    if str_stack.size() == 0:
                        str_stack.push(str_one)
                    else:
                        if str_stack.peek() != '{':
                            break
                        else:
                            str_stack.pop()
                if str_one == ']':
                    if str_stack.size() == 0:
                        str_stack.push(str_one)
                    else:
                        if str_stack.peek() != '[':
                            break
                        else:
                            str_stack.pop()
                if str_one == ')':
                    if str_stack.size() == 0:
                        str_stack.push(str_one)
                    else:
                        if str_stack.peek() != '(':
                            break
                        else:
                            str_stack.pop()
    
    if str_stack.size() == 0:
        print('输入括号匹配')
    else:
        print('输入括号不匹配')
        
if __name__ == "__main__":
    str = input('请输入字符:')
    test_str(str)