【小米OJ-括号配对】栈的使用

#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;
}
不忘初心,方得始终。只有走过弯路,才更确信当初最想要的是什么。

浙公网安备 33010602011771号