Parentheses Balance UVA

来源:互联网 发布:java基础pdf 编辑:程序博客网 时间:2024/06/03 12:03

问题类型:stack,极简主义代码~

问题链接
03pie’s solution for [UVA-673]:

#include<bits/stdc++.h>using namespace std;int main(){     int n;    cin>>n;getchar();//得到n值,且吃掉回车     while(n--){        stack<char> s;        char x;        while((x=getchar())!='\n'&&x!=EOF){//过滤回车             if(!s.empty()&&x!=' '){ //过滤空格                 if(x==')'&&s.top()=='('||x==']'&&s.top()=='[')  s.pop();                else s.push(x);            }            else if(x!=' ') s.push(x);        }        if(s.empty())   cout<<"Yes\n";        else    cout<<"No\n";    }    return 0;}
0 0
原创粉丝点击