Train Problem I

http://acm.hdu.edu.cn/showproblem.php?pid=1022

栈的模板题。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<stack>
 4 #include<string>
 5 #include<cstring>
 6 using namespace std;
 7 string a,b;
 8 int c[100];
 9 int main()
10 {
11     //  freopen("1.txt","r",stdin);
12     int n;
13     stack<char>jk;
14     while(scanf("%d",&n)!=EOF)
15     {
16         stack<int>jk;
17         while(!jk.empty())
18             jk.pop();
19         cin>>a>>b;
20         int k=0,j=0;
21         for(int i=0; i<n; i++)
22         {
23             jk.push(a[i]);
24             c[k++]=1;
25             while(j<n && !jk.empty())
26             {
27                 if(jk.top()==b[j])
28                 {
29                     j++;
30                     jk.pop();
31                     c[k++]=0;
32                 }
33                 else
34                     break;
35             }
36         }
37 
38         if(jk.empty())
39         {
40             cout<<"Yes."<<endl;
41             for(int i=0; i<k; i++)
42             {
43                 if(c[i]==1)
44                     cout<<"in"<<endl;
45                 else
46                     cout<<"out"<<endl;
47             }
48             cout<<"FINISH"<<endl;
49         }
50         else
51             cout<<"No."<<endl<<"FINISH"<<endl;
52     }
53     return 0;
54 }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值