HDOJ1022

来源:互联网 发布:查看java进程 编辑:程序博客网 时间:2024/06/01 10:44
#include <iostream> 
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <stack>


using namespace std;


string s1, s2;
stack<char> sta;




int main()
{
int n;
while (cin >> n)
{
getchar();
cin >> s1 >> s2;
int now = 0;
sta.push(s1[now++]);
for (int i = 0; i < s2.length(); i++)
{
while (sta.empty()||sta.top() != s2[i])
{
if (now >= s1.length())break;
   sta.push(s1[now++]);
}
if (sta.top() == s2[i]) sta.pop();
}
if (!sta.empty())
{
cout << "No." << endl << "FINISH" << endl;
while (!sta.empty()) sta.pop();  //清空栈
}
else
{
cout << "Yes." << endl;
now = 0;
sta.push(s1[now++]);
cout << "in" << endl;
for (int i = 0; i < s2.length(); i++)
{
while (sta.empty() || sta.top() != s2[i])
{
if (now >= s1.length())break;
sta.push(s1[now++]);
cout << "in" << endl;
}
if (sta.top() == s2[i])
{
sta.pop();
cout << "out" << endl;
}
}
cout << "FINISH" << endl;
}
}
return 0;
}