
#include <bits/stdc++.h>
using namespace std;
int main()
{
// please write your code here
stack<int>st;
string str;
while(cin>>str){
while(!st.empty()) st.pop();
for(int i=0;i<str.size();i++){
if(st.empty()) st.push(str[i]);
else if(st.top()==‘[‘&&str[i]==‘]‘) st.pop();
else if(st.top()==‘(‘&&str[i]==‘)‘) st.pop();
else if(st.top()==‘{‘&&str[i]==‘}‘) st.pop();
else st.push(str[i]);
}
if(st.empty()) cout<<1<<endl;
else cout<<0<<endl;
}
return 0;
}
原文:https://www.cnblogs.com/wszhu/p/12804377.html