#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
    int  stack[20],len,in[10],out[20],count[20];
    int *pp=NULL,*p,top,*q,i,n;
    char strin[10],strout[10];
    while(cin>>n)
    {
        cin>>strin>>strout;
        len=strlen(strin);
        for(i=0;i<len;i++)
        {
            in[i]=strin[i]-'0';
            out[i]=strout[i]-'0';
        }
        memset(stack,0,sizeof(stack));
        memset(count,-1,sizeof(count));
        pp=&in[len-1];
        p=in;
        q=out;
        i=0;
        top=-1;
    //    cout<<*p<<' '<<*q;
        while(p<=pp)
        {
            stack[top+1]=*p;
            top++;
            count[i++]=1;
       
            while(stack[top]==*q)
            {
                stack[top--]=0;
                count[i++]=0;
                q++;
                if(top==-1)
                    break;
            }
                p++;
        }
        if(top==-1)
        {
            cout<<"Yes."<<endl;
            for(int k=0;k<i;k++)
            {
                if(count[k]==1)
                    cout<<"in"<<endl;
                else if(count[k]==0)
                    cout<<"out"<<endl;
            }
            cout<<"FINISH"<<endl;
        }
        else
            cout<<"No."<<endl<<"FINISH"<<endl;
       strcpy(strin,"0");strcpy(strout,"0");
    }
    return 0;
}

很粗糙的栈,也搞了半天,哎~~

一运行就爆内存错误,卡,,,吃完饭后才发现  * pp=&in[len-1];

这里多了一个*号,,小心使得万年船啊。。。改了半天,之后还改反了:把 while(cin>>n)改成了

while(scanf("%d %s %s"),&n,strin,strout)缺少了终止条件,怪不得outpu time limits…………

posted on 2011-04-23 21:23  cchun  阅读(214)  评论(0编辑  收藏  举报