1004 Anagrams by Stack
来源:互联网 发布:深圳程序员工资2016 编辑:程序博客网 时间:2024/06/10 10:34
// C++Exercise.cpp : 定义控制台应用程序的入口点。//#include<iostream>#include<string>#include<stack>using namespace std;string first, second;int len;void dfs(stack<char> &st,stack<char> data,int n_push,int n_pop){if (n_push == len&&n_pop == len){stack<char> out;stack<char> st1 = st;while (!st1.empty()){char temp = st1.top();st1.pop();out.push(temp);}while (!out.empty()){cout << out.top();out.pop();cout << " ";}cout <<endl;return;}if (n_push < len){st.push('i');data.push(first[n_push]);n_push++;dfs(st,data,n_push,n_pop);data.pop();st.pop();n_push--;}if (!data.empty() &&n_pop<len&& data.top() == second[n_pop]){data.pop();n_pop++;st.push('o');dfs(st, data, n_push, n_pop);st.pop();n_pop--;}}int main(){while (cin >> first >> second){cout << '[' << endl;if (first.size() == second.size()){len = first.size();stack<char> st;stack<char> data;dfs(st,data,0,0); }cout << ']' << endl;}return 0;}
阅读全文
0 0
- 1004 :Anagrams by Stack
- 1004 Anagrams by Stack
- ZOJ-1004-Anagrams by Stack
- ZOJ 1004 Anagrams by Stack
- ZOJ 1004 Anagrams by Stack
- ZJU 1004 Anagrams by Stack
- zoj 1004 Anagrams by Stack
- zoj 1004 Anagrams by Stack
- zoj 1004 Anagrams by Stack
- ZOJ 1004Anagrams by Stack
- ZOJ 1004 Anagrams by Stack
- ZOJ 1004 Anagrams by Stack
- ZOJ 1004Anagrams by Stack
- ZOJ(1004)Anagrams by Stack (DFS+stack)
- zoj 1004 Anagrams by Stack (回溯)
- ZOJ Problem Set - 1004 Anagrams by Stack
- ZOJ 1004 Anagrams by Stack(dfs堆栈)
- ZOJ 1004 Anagrams by Stack(dfs堆栈)
- NYOJ 一笔画问题
- wxPython:实现俄罗斯方块
- 洛谷P3327:[SDOI2015]约数个数和 (莫比乌斯反演)
- nginx实现负载均衡
- TensorFlow实现MLP(多层感知机)
- 1004 Anagrams by Stack
- JaveScript之关于时间的函数
- CNN文本分类
- 决策树
- Length of Last Word
- C++广度优先搜索算法之走出迷宫
- The server does not support version 3.0 of the J2EE Web module specification解决方案
- JavaScript(1)
- 树莓派3b no wireless interfaces found 的解决办法 360wifi和树莓派结合