出栈入栈合法性 题解:
#include<bits/stdc++.h>
using namespace std;
int main() {
string s;
stack<char> sta;
cin>>s;
for (int i = 0; i < s.length(); ++i) {
if(s[i]=='A') sta.push(s[i]);
if(s[i]=='D'){
if (sta.empty()){
cout<<"no";
return 0;
}else{
sta.pop();
}
}
}
cout<<"yes";
return 0;
}
登录后发布评论
暂无评论,来抢沙发