ZOJ Problem Set - 1004-Anagrams by Stack
来源:互联网 发布:好玩的微软软件 编辑:程序博客网 时间:2024/05/06 17:26
唉!先直接上源代码吧!什么时候有时间的再来加说明!
#include<iostream>#include<vector>#include<stack>#include<deque>#include<algorithm>#include<iterator>using namespace std;/**i代表PUSH,o代表POP*/bool judge(deque<char> sou,deque<char> des,vector<char> & res){stack<char> inistack;for(vector<char>::iterator iter = res.begin();iter!=res.end();iter++){ if('i' == *iter) { inistack.push(sou.front()); sou.pop_front(); } else { if(des.front() != inistack.top()) return false; des.pop_front(); inistack.pop(); }}return true;}void fun(deque<char>& sou,deque<char>& des,vector<char> & res){if(res.size() >= 2*sou.size()){if(judge(sou,des,res))//输出结果{copy(res.begin(),res.end(),ostream_iterator<char>(cout," "));cout<<endl;} return;}for (int i = 0; i <= 6; i+=6){if(6==i&&(count(res.begin(),res.end(),'o')>=count(res.begin(),res.end(),'i')))continue;if(0==i&&((count(res.begin(),res.end(),'i')-count(res.begin(),res.end(),'o'))>=(2*sou.size()-res.size()) ))continue;res.push_back('i'+i);fun(sou,des,res);res.pop_back();}}int main(){deque<char> source,desti;vector<char> res;copy(istream_iterator<char>(cin),istream_iterator<char>(),inserter(source,source.end()));cin.clear();copy(istream_iterator<char>(cin),istream_iterator<char>(),inserter(desti,desti.end()));fun(source,desti,res);return 0;}
1 0
- ZOJ Problem Set - 1004 Anagrams by Stack
- ZOJ Problem Set - 1004-Anagrams by Stack
- ZOJ-1004-Anagrams by Stack
- ZOJ 1004 Anagrams by Stack
- ZOJ 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 1004 Anagrams by Stack(dfs堆栈)
- ZOJ 1004 Anagrams by Stack(dfs堆栈)
- 浙大ZOJ 1004 Anagrams by Stack问题解决
- [JAVA][ZOJ 1004][Anagrams by Stack]
- 第十一周项目一(2)
- OpenCV成长之路(9):特征点检测与图像匹配
- 计算机是如何启动的?
- 确保 PHP 应用程序的安全
- centos 安装nodejs 和npm
- ZOJ Problem Set - 1004-Anagrams by Stack
- LeetCode[string]: Length of Last Word
- OpenCV成长之路(8):直线、轮廓的提取与描述
- git 的使用-linux上的配置 -ssh
- [IOS]UIColor,CGColor,CIColor三者的区别和联系
- [NIOS II] LED实验与中断实验
- UVALive - 2519 Radar Installation
- 使用 JMeter 对 SOAP 应用进行压力或性能测试
- CentOS英文环境下使用中文输入法