文章

3

粉丝

0

获赞

0

访问

166

头像
出栈入栈合法性 题解:
P2005 东北大学机试题
发布于2025年1月28日 22:56
阅读数 49

#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;
}
 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发