题目大意:规定 i 为入栈,o 为出栈,现在给两个字符串st1,st2,现在要将st1转化为st2,转化方法是,st1中字符从头开始入栈,并合理出栈构造出st2。请输出所有可能的出入栈步骤。

深度优先搜索+回溯~

#include<bits/stdc++.h>
using namespace std;
string s1,s2;
int len;
stack<char> st;
vector<char> path;
void dfs (int ipush,int ipop) {
if (ipush==len&&ipop==len) {
for (int i=;i<path.size();i++)
printf ("%c ",path[i]);
printf ("\n");
return;
}
if (ipush+<=len) {
st.push(s1[ipush]);
path.push_back('i');
dfs(ipush+,ipop);
st.pop();
path.pop_back();
}
if (ipop+<=len&&!st.empty()&&st.top()==s2[ipop]) {
char now=st.top();
st.pop();
path.push_back('o');
dfs(ipush,ipop+);
st.push(now);
path.pop_back();
}
}
int main () {
while (cin>>s1>>s2) {
len=s1.length();
printf ("[\n");
dfs(,);
printf ("]\n");
}
return ;
}

最新文章

  1. 关于easyui datagrid 表格数据处理
  2. kali 更改root密码
  3. js动画之链式运动
  4. Python-10 字典
  5. c++ 11 sleep()
  6. 如何使用国内源部署Ceph?
  7. 用super daemon xinetd进行安全配置
  8. python基础整理笔记(一)
  9. update kernel
  10. gulp入门
  11. DB天气app冲刺第四天
  12. Hdu 3887 Counting Offspring \ Poj 3321 Apple Tree \BZOJ 1103 [POI2007]大都市meg
  13. Demo_塔防(自动生成怪物,导航,炮塔攻击,怪物掉血死忙)
  14. 勉強すべきURL
  15. zf-关于荆州首页鼠标移动到导航栏上去触发的js 显示 问题解决办法
  16. 消息中间件 MQ
  17. JavaWeb过滤器.监听器.拦截器-原理&区别-个人总结
  18. 关于Flume中Chanel.Selector.header解释
  19. Android 阴影,圆形的Button
  20. iOS 模拟器的“调试-位置”总是变成无的问题

热门文章

  1. AcWing 831. KMP字符串
  2. 题解【洛谷P3884】[JLOI2009]二叉树问题
  3. mvn + testng + allure 生成自动化测试报告
  4. docker启动容器报错:iptables failed
  5. Makefile的编写及四个特殊符号的意义@、$@、$^、$
  6. Palindromes _easy version 题解
  7. hdu 1532 Drainage Ditches(网络流)
  8. bistoury建库建表(一)
  9. 对象析构谈—— delete this 的使用及注意事项
  10. vue项目怎么搭建到云服务器上