标签:lan scanf clu stream 记录 else lse nis names
#include<iostream>
#include<stack>
#include<vector>
#include<cstring>
using namespace std;
int n;
char s1[10], s2[10];
vector<int> p; //记录顺序
stack<char> st;
bool solve()
{
int a = 0, b = 0;
while(a < n && b < n)
{
if(!st.empty())
{
if(st.top() == s2[b]) //出
{
p.push_back(2);
b++;
st.pop();
}
else //入
{
p.push_back(1);
st.push(s1[a]);
a++;
}
}
else //入
{
p.push_back(1);
st.push(s1[a]);
a++;
}
}
while(b < n)
{
if(st.top() == s2[b]) //出
{
p.push_back(2);
b++;
st.pop();
}
else return false;
}
return true;
}
int main()
{
while(~scanf("%d", &n))
{
while(!p.empty()) p.pop_back();
while(!st.empty()) st.pop();
cin >> s1 >> s2;
if(!solve()) cout << "No.\nFINISH\n";
else
{
cout << "Yes.\n";
for(int i = 0; i < p.size(); i++)
{
if(p[i] == 1) cout << "in\n";
else if(p[i] == 2) cout << "out\n";
}
cout << "FINISH\n";
}
}
return 0;
}
标签:lan scanf clu stream 记录 else lse nis names
原文地址:https://www.cnblogs.com/znk97/p/14345337.html