#include<string>
#include<iostream>
#include<stack>
using namespace std;
string s1;
string s2;
string s;
string action;
stack<char> stak;
int pos1, cur;
void push()
{
stak.push(s1[pos1]);
pos1++;
action += "i";
}
void pop()
{
char ch = stak.top();
stak.pop();
action += "o";
s += ch;
cur++;
}
void print()
{
for (int i = 0; i < action.size(); i++)
cout << action[i] << " ";
cout << endl;
}
void dfs()
{
if (cur>0 && s[cur - 1] != s2[cur - 1])
return;
if (cur == s1.size())
{
print();
return;
}
string temp_s1 = s1, temp_s2 = s2, temp_s = s, temp_action = action;
stack<char> temp_stak = stak;
int temp_pos1 = pos1, temp_cur = cur;
if (pos1 < s1.size())
{
push();
dfs();
}
s1 = temp_s1;
s2 = temp_s2;
s = temp_s;
action = temp_action;
stak = temp_stak;
pos1 = temp_pos1;
cur = temp_cur;
if (!stak.empty())
{
pop();
dfs();
}
}
int main()
{
while (cin >> s1 >> s2)
{
s = action = "";
stak = stack<char>();
pos1 = 0;
cur = 0;
cout << "[" << endl;
dfs();
cout << "]" << endl;
}
return 0;
}
Zoj1004
最新推荐文章于 2022-12-05 09:06:12 发布
