文章
166
粉丝
68
获赞
1000
访问
143.3k
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s;
	while(cin>>s){
	    stack<char>st;
	    bool flag=true;
	    for(auto x:s){
	        if(x=='('||x=='['){
	            st.push(x);
	        }else{
	            if(st.empty()){
	                flag=false;
	                break;
	            }else{
	                char t=st.top();
	                if((t=='('&&x==')')||(t=='['&&x==']')){
	                    st.pop();
	                }else{
	                    flag=false;
	                    break;
	                }
	            }
	        }
	    }
	    if(!st.empty())flag=false;
	    if(flag)cout<<1<<endl;
	    else cout<<0<<endl;
	}
}
只需要左输入,右判断即可完成任务。
登录后发布评论
暂无评论,来抢沙发