zoukankan      html  css  js  c++  java
  • HDU

    compile error两遍。

    原因:没考虑栈为空的情况

    代码:

    #include<cstdio>
    #include<iostream>
    #include<stack>
    #include<string>
    #include<cstring>
    using namespace std;
    int n;
    char s1[11],s2[12];
    stack<char>q;
    string ans;
    
    int main()
    {
        while(~scanf("%d%s%s",&n,s1,s2))
        {
            int flag=1;
            while(!q.empty())
                q.pop();
            ans.clear();
    
            int it=-1;
            for(int i=0; i<n;)
            {
                if(q.empty())
                {
                    q.push(s1[++it]);
                    ans+="in
    ";
                }
                else
                {
                    if(q.top()==s2[i])
                    {
    
                        q.pop();
                        ans+="out
    ";
                        i++;
                    }
                    else
                    {
                        if(it==n-1)
                        {
                            //cout<<"2 ";
                            flag=0;
                            break;
                        }
                        else
                        {
                            //cout<<"3 ";
                            ans+="in
    ";
                            q.push(s1[++it]);
                        }
                    }
                }
            }
    
    
            if(flag)
            {
                cout<<"Yes."<<endl;
                cout<<ans;
                cout<<"FINISH
    ";
            }
            else
            {
                cout<<"No.
    FINISH
    ";
            }
        }
    
        return 0;
    }
  • 相关阅读:
    吉他 摄影
    前端思考独处时间自我成长
    约束力
    js算法
    旅行计划
    生产者消费者问题
    Lock锁
    线程和进程
    什么是JUC
    GC日志分析和垃圾回收器的新展望
  • 原文地址:https://www.cnblogs.com/pipitongkw1/p/10701900.html
Copyright © 2011-2022 走看看