HDU 1022 Train Problem I

栈的基本操作……

#include <cstdio>

#include <cstring>

#include <stack>

using namespace std;

char in[100],out[100];

int flag[200];

int main(){

    int n,top,i,j,k,bo;

    while(scanf("%d",&n)!=EOF){

        stack s;

        scanf("%s%s",&in,&out);

        top=i=j=k=0; bo=1;

        while(j<n){

            if(in[i]==out[j]){

                flag[k++]=0; flag[k++]=1;

                i++; j++;

            }    

            else if((!s.empty())&&s.top()==out[j]){

                flag[k++]=1;

                s.pop(); j++;

            }  

            else if(i<n)s.push(in[i++]),flag[k++]=0;   

            else{bo=0;break;}

        }    

        if(bo==0)printf("No.\n");

        else{

            printf("Yes.\n");

            for(int p=0;p<k;p++){

                if(flag[p]==0)printf("in\n");

                else printf("out\n");

            }    

        }    

        printf("FINISH\n");

    }    

    return 0;

}    

你可能感兴趣的:(HDU)