码迷,mamicode.com
首页 > 其他好文 > 详细

栈、队列

时间:2016-06-10 16:17:02      阅读:106      评论:0      收藏:0      [点我收藏+]

标签:

hdu 1022

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<cctype>
#include<algorithm>
#include <vector>
#include <stack>
#include <queue>

using namespace std;
#define INF 0x3f3f3f3f
#define N 550

int main()
{
    int n;
    char a[N], b[N];

    stack <char> s;
    queue <char> q;


    while(~scanf("%d", &n))
    {
        memset(a, 0, sizeof(a));
        memset(b, 0, sizeof(b));
        scanf("%s%s", a, b);
        while(!s.empty()) s.pop();
        while(!q.empty()) q.pop();

        int i, j;
        i=j=0;

        while(i<n)
        {
            s.push(a[i]);
            q.push(1);
            while(!s.empty()&&s.top()==b[j])
            {
                s.pop();
                q.push(0);
                j++;
            }
            i++;
        }

        if(s.empty())
        {
            printf("Yes.\n");
            while(!q.empty())
            {
                if(q.front()) printf("in\n");

                else printf("out\n");

                q.pop();
            }
        }
        else
            printf("No.\n");
        printf("FINISH\n");
    }

    return 0;
}

 

栈、队列

标签:

原文地址:http://www.cnblogs.com/9968jie/p/5573782.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!