就是利用栈模拟火车出栈进栈
#include <iostream>
#include <cstring>
#include <stack>
#include <algorithm>
#include <cstdio>
#define MAX 100
using namespace std;
int n;
char o1[MAX] , o2[MAX];
char s[MAX][MAX];
stack<char> stk;
bool used[MAX];
int cnt;
bool check ( )
{
memset ( used , 0 , sizeof ( used ) );
while ( !stk.empty() ) stk.pop();
cnt = 0;
int j = 0;
for ( int i = 0 ; i < n ; i++ )
{
while ( j < n &&!used[o2[i]] )
{
used[o1[j]] = true;
//s[cnt++] = in;
strcpy ( s[cnt++] , "in" );
stk.push ( o1[j++] );
}
if ( stk.top() == o2[i] ) stk.pop();
else return false;
//s[cnt++] = out;
strcpy( s[cnt++] , "out" );
}
return true;
}
int main ( )
{
while ( ~scanf ( "%d" , &n ) )
{
scanf ( "%s" , o1 );
scanf ( "%s" , o2 );
if ( check ( ) )
{
puts ( "Yes." );
for ( int i = 0 ; i < cnt ; i++ )
puts ( s[i] );
}
else puts ( "No." );
puts ( "FINISH" );
}
}