杭电1022 Train Problem I

/*********************************
 *    日期:2011-3-12
 *    作者:SJF
 *    题号:杭电1022
 *    题目:Train Problem I
 *    结果:AC
 *    题意:
 *    总结:
**********************************/
#include<iostream>
#include<stack>
#include<string>
using namespace std;
int main( )
{
    int N;
    char train1[1002],train2[1002];
    string mark[100];
    while(scanf("%d",&N)!=EOF)
    {
        stack<char> s;
        int i,j=0,k=0;
        scanf("%s %s",train1,train2);
        for(i=0;i<N;i++)//i  train1  k  train2  j  mark
        {
            s.push(train1[i]);
            mark[j++]="in";
            while(!s.empty()&&s.top()==train2[k])
            {
                mark[j++]="out";
                s.pop();
                k++;
            }
        }
        if(s.empty())
        {
           cout<<"Yes."<<endl;
           for(i=0;i<j;i++)
               cout<<mark[i]<<endl;     
           cout<<"FINISH"<<endl;
        }
        else
        {
            cout<<"No."<<endl;
            cout<<"FINISH"<<endl;
        }
    }
    return 0;
}

转载于:https://www.cnblogs.com/snake-hand/archive/2011/10/28/2454450.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值