hdu1022 Train Problem I

#include <iostream>
#include <stack>
#include <cstring>
using namespace std;

stack<int>st;
int flag[100002];
char in[50001],out[50002];

int main()
{
	int n,i,j,k;
	while(scanf("%d",&n)!=EOF)
	{
		scanf("%s %s",in,out);
		i=j=k=0;
		while(!st.empty())
			st.pop();
		while(j<=n&&i<n)
		{
			if(!st.empty()&&st.top()==out[i])
			{
				flag[k++]=1;
				i++;
				st.pop();
			}
			else
			{
				st.push(in[j++]);
				flag[k++]=0;
			}
		}
		if(k!=2*n)
			printf("No.\n");
		else
		{
			printf("Yes.\n");
			for (i=0;i<k;i++)
			{
				if(flag[i])
					printf("out\n");
				else
					printf("in\n");
			}
		}
		printf("FINISH\n");
	}
	return 0;
}

你可能感兴趣的:(hdu1022 Train Problem I)