文章

20

粉丝

0

获赞

64

访问

11.1k

头像
出栈入栈合法性 题解:
P2005 东北大学机试题
发布于 2026年3月
阅读数 562

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
    string s;
    cin>>s;
    stack<char> a;
    int len=s.size();
    int i=0;
    for(i;i<len;i++){
        if(s[i]=='A'){
            a.push(s[i]);
        }else if(s[i]=='D'){
            if(a.empty()){
                cout<<"no"<<endl;
                break;
            }else{
                a.pop();
            }
        }
    }
    if(a.empty()&&i==len){
        cout<<"yes"<<endl;
    }
    return 0;
}
 



登录后发布评论

暂无评论,来抢沙发