文章

3

粉丝

0

获赞

15

访问

1.2k

头像
模拟出入栈游戏 题解:
P1684 中南大学机试题
发布于2025年3月18日 16:56
阅读数 556

#include<bits/stdc++.h>
#include<stack>
using namespace std;
bool isValid(string &str){
    stack<char> s;
    
    int index=0;
    for(char i='a';i<='z';i++){
        s.push(i);//将26个字母按顺序入栈
        while(!s.empty()&&s.top()==str[index]){//看看出栈顺序是不是26个字母顺序
            s.pop();
            index++;
        }
    }
    return index==str.size();
}
int main(){
    string s;
    while(cin>>s){
        if(isValid(s)){
            cout<<"yes"<<endl;
        }else{
     &nbs...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发