栈的简单应用 HDU 1022 http://acm.hdu.edu.cn/showproblem.php?pid=1022

#include<stdio.h>
#include<stack>
#include<string.h>
#define N 20

using namespace std;

int main()
{
    stack<char>S;
    int n, i, j, k, a[N];
    char s1[N], s2[N];
    while(scanf("%d", &n) != EOF)
    {
        while(!S.empty())//清空栈
            S.pop();
        scanf("%s%s", s1, s2);
        j = k = 0;
        memset(a, 0, sizeof(a));
        for(i = 0 ; i < n ; i++)
        {
            S.push(s1[i]);//入栈
            a[k++] = 1//进栈标记
            while(!S.empty() && S.top() == s2[j])//栈首相同
            {
                a[k++] = 0;//出栈标记
                S.pop();//出栈
                j++;//j右移
            }
        }
        if(j == n)
        {
            printf("Yes.\n");
            for(i = 0 ; i < k ; i++)
                if(a[i] == 1)
                    printf("in\n");
                else
                    printf("out\n");
        }
        else
            printf("No.\n");
        printf("FINISH\n");
    }
    return 0;
}

 

posted @ 2015-05-07 17:59  午夜阳光~  阅读(128)  评论(0编辑  收藏  举报