首页 > 代码库 > hdu1022 train problem 栈的应用

hdu1022 train problem 栈的应用

#include 
#include 
#include 

using namespace std;
int main()
{
    int n;
    while(cin >> n)
    {
        stack one;
        string od1,od2;
        bool state[10001];
        cin  >> od1 >> od2;
        int from  = 0 , to = 0;
        int i = 0;
        while(from < n)
        {
            while(od1[from] != od2[to])
                one.push(od1[from++]),state[i++] = false;
            one.push(od1[from++]),state[i++] = false;
            while(!one.empty() && one.top() == od2[to] )
            {
                one.pop();
                to++;
                state[i++] = true;
            }

        }
        if(to < n - 1)
            cout << "No.\n";
        else
        {
            cout << "Yes.\n";
            for(int i = 0 ;i < 2 * n; i++)
            {
                if(state[i])
                    cout << "out\n";
                else

                    cout << "in\n";
            }
        }
        cout << "FINISH\n";
    }
    return 0;
}