#include<iostream> #include<stack> using namespace std; int main(){ string a; cin>>a; stack<char> m; for(int i=0;i<a.length();i++){ if(a[i]=='('||a[i]=='['||a[i]=='{'){ m.push(a[i]); } if(a[i]==')'||a[i]==']'||a[i]=='}'){ if(m.top()=='('&&a[i]==')'||m.top()=='['&&a[i]==']'||m.top()=='{'&&a[i]=='}'){ m.pop(); }else{ cout<<"false"; return 0; } } } if(m.empty()){ cout<<"true"; } return 0; }
标签:std,main,匹配,int,括号,include From: https://www.cnblogs.com/wangyueshuo/p/18020730