文章

20

粉丝

0

获赞

56

访问

3.8k

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

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

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发