唉!先直接上源码吧!什么时候有时间的再来加说明。

#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;
}

ZOJ Problem Set - 1004-Anagrams by Stack的更多相关文章

  1. [ZJU 1004] Anagrams by Stack

    ZOJ Problem Set - 1004 Anagrams by Stack Time Limit: 2 Seconds      Memory Limit: 65536 KB How can a ...

  2. stack+DFS ZOJ 1004 Anagrams by Stack

    题目传送门 /* stack 容器的应用: 要求字典序升序输出,所以先搜索入栈的 然后逐个判断是否满足答案,若不满足,回溯继续搜索,输出所有符合的结果 */ #include <cstdio&g ...

  3. ZOJ 1004 Anagrams by Stack

    Anagrams by Stack 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1004 题意:通过堆栈实现将一 ...

  4. ZOJ 1004 Anagrams by Stack(DFS+数据结构)

    Anagrams by Stack 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4 题目大意:输入两个字符串序列,判 ...

  5. [ZOJ 1004] Anagrams by Stack (简单搜索)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1004 题目大意:给你个栈,给你源串和目标串,按字典序输出符合要求 ...

  6. ZOJ Problem Set - 1004

    1.翻译参考 http://liucw.blog.51cto.com/6751239/1198026 2.代码参考 http://www.cnblogs.com/devymex/archive/201 ...

  7. 1004 Anagrams by Stack

    考察DFS的应用,用栈描述字符串的变化过程. #include <stdio.h> #include <string.h> int len1,len2; ],str2[],st ...

  8. Anagrams by Stack(深度优先搜索)

    ZOJ Problem Set - 1004 Anagrams by Stack Time Limit: 2 Seconds      Memory Limit: 65536 KB How can a ...

  9. HDU ACM 1515 Anagrams by Stack

    Anagrams by Stack Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  10. ZOJ Problem Set - 1394 Polar Explorer

    这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...

随机推荐

  1. excel如何快速实现数据区域的框选

    这里会存在2个情况,一个是快速的选择一行或者一列的数据,另外一个是快速的选择一块的数据(数据区域) 1.当有上万条数据时,怎么快速的选择一行或一列的数据? 方法:将鼠标放在需要选择的数据区域的开头位置 ...

  2. python之函数用法get()

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法get() #http://www.runoob.com/python/att-dic ...

  3. Centos6下编译安装gcc6.4.0

    Centos6自带的gcc4.4.7不支持c++11, 于是编译安装最新版的gcc wget https://gmplib.org/download/gmp/gmp-6.1.2.tar.xz .tar ...

  4. PL/SQL Developer 中文乱码问题的解决

    分三个步骤解决: 1.检查server编码:         运行SQL语法: select * from v$nls_parameters;   2.设置本地client编码:        进入 ...

  5. win32下编译glog

    既然编译第三方库了,google提供的VSproject是老版本的,构建不好升级.所以还是用cmake是王道. 采用out of source 编译,  以下是编译脚本bat: mkdir build ...

  6. 2016年排名Top 100的Java类库——在分析了47,251个依赖之后得出的结论(16年文章)

    本文由HollisChuang 翻译自 The Top 100 Java Libraries in 2016 – After Analyzing 47,251 Dependencies . 原作者:H ...

  7. Docker运行python容器

    容器是镜像运行的实例,而镜像保存在仓库里,测试或者发布生产环境只需要pull下来即可,相对传统的应用部署,能很好的保持环境的一致,节省运维时间.最近公司内部的java和.net服务也已经全部容器化,实 ...

  8. 听听各位对Ubuntu的UI的看法

    2012-7-15 15:46    最近升级到Ubuntu 12.4 .发现其界面效果真的时越来越炫啦.我就在想,你Ubuntu你图什么啊, 你是以个Linux系统,你的重点在于让系统运行更稳定,更 ...

  9. ajax请求格式

    ajax请求格式........... var rowsData = $('#receiptPrintList').datagrid('getSelections'); $.ajax({ type: ...

  10. eclipse的jdk版本和spring冲突问题WARN XmlWebApplicationContext:1060 - Exception thrown from LifecycleProcessor on context close

    项目环境: jdk1.8 tomcat7 问题:eclipse启动tomcat后控制台报如下错误: WARN XmlWebApplicationContext:1060 - Exception thr ...