HDU 1022 Train Problem I

来源:互联网 发布:临高启明知乎 编辑:程序博客网 时间:2024/04/30 04:47

栈模拟

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <math.h>using namespace std;#define sf scanf#define pf printf#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)#define dbg(x) cerr << "Line:" <<  __LINE__ << " : " << #x << " = " << (x) << endl#define nMax 1000#define ll long longint n;string s1,s2;int in[nMax];int ans[nMax];char st[nMax];int top;void go() {top = 0;int i,j,m=0;i = 0;j = 0;int l = s1.length();//st[++top] = i;in[i]=1;i++;while(j < l) {if(top && s2[j]==s1[st[top]]) {ans[m++]=-1;top --;j++;}else {if(i==l) break;ans[m++]=1;st[++top]=i;in[i]=1;i++;}}if(j!=l) {pf("No.\n");pf("FINISH\n");}else {pf("Yes.\n");rep(i,m) {pf("%s\n",ans[i]==1?"in":"out");}pf("FINISH\n");}return ;}int main() {#ifndef ONLINE_JUDGEfreopen("in.txt","r",stdin);#endifwhile(cin >> n >> s1 >> s2) {go();}return 0;}


原创粉丝点击