UVa673 - Parentheses Balance

            
//UVa673 - Parentheses Balance

//已AC

include

include

include

using namespace std;
int main(){
int T;
cin>>T;
getchar(); //cin.get(); 读取整数后面的第一个换行符,防止误导后面的getline();
while(T--){
string str;
stacks;
getline(cin,str); //读取包括换行符在内的一整行(但是不输出换行符??)
int ok = 1;
for(int i = 0; i < str.size(); i++){
if(str[i] == '(' || str[i] == '[') s.push(str[i]);
else if(!s.empty()&& s.top() == '(' && str[i] == ')') s.pop();
else if(!s.empty()&& s.top() == '[' && str[i] == ']') s.pop();
else ok = 0;
}
ok&&s.empty()? cout<<"Yes\n": cout<<"No\n";
}
return 0;
}

点赞

发表评论

昵称和uid可以选填一个,填邮箱必填(留言回复后将会发邮件给你)
tips:输入uid可以快速获得你的昵称和头像