hdu 1022 Train Problem I 堆栈

#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <iostream>
#include <algorithm>
using namespace std;
int c[11];
int e[22];
int main()
{
    int n;
    char a[11],b[11];
    while(cin>>n)
    {
        int i,j,k,flag=0,t=0;
        cin>>a>>b;
        stack<int>q;
        i=j=0;
        while(i<n)
        {
            while(j<n&&a[j]!=b[i])
            {
                q.push(a[j]-'0');
                e[t++]=0;
                j++;

            }
            if(j==n){flag=1;break;}
            q.push(a[j]-'0');
            j++;
            e[t++]=0;
            while(!q.empty()&&q.top()==b[i]-'0')
            {

                q.pop();
                e[t++]=1;
                i++;
            }
        }
        if(flag)cout<<"No."<<endl<<"FINISH"<<endl;
        else
        {
            cout<<"Yes."<<endl;
            for(i=0;i<t;i++)
                if(e[i]==0)cout<<"in"<<endl;
                else cout<<"out"<<endl;
            cout<<"FINISH"<<endl;
        }
    }
    return 0;
}

你可能感兴趣的:(hdu 1022 Train Problem I 堆栈)