HDU - 1022

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\n";
            }
            else
            {
                if(q.top()==s2[i])
                {

                    q.pop();
                    ans+="out\n";
                    i++;
                }
                else
                {
                    if(it==n-1)
                    {
                        //cout<<"2 ";
                        flag=0;
                        break;
                    }
                    else
                    {
                        //cout<<"3 ";
                        ans+="in\n";
                        q.push(s1[++it]);
                    }
                }
            }
        }


        if(flag)
        {
            cout<<"Yes."<<endl;
            cout<<ans;
            cout<<"FINISH\n";
        }
        else
        {
            cout<<"No.\nFINISH\n";
        }
    }

    return 0;
}

 

posted @ 2019-04-13 17:08  pipitongkw1  阅读(87)  评论(0编辑  收藏  举报