首页 > 其他 > 详细

hdu1022 train problem 栈的应用

时间:2014-05-21 23:49:23      阅读:535      评论:0      收藏:0      [点我收藏+]
#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;
}

 

hdu1022 train problem 栈的应用,布布扣,bubuko.com

hdu1022 train problem 栈的应用

原文:http://www.cnblogs.com/congluwen/p/3739086.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!