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

#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文件批量重命名

    1.创建bat文件 2.在文件内输入以下格式的内容并保存,注意期间有空格 ren 1.txt 0011.txt     ren 2.txt 0021.txt     ren 3.txt 0031.tx ...

  2. PHP 调用ffmpeg

    PHP 调用ffmpeg linux ffmpeg安装,tar文件安装一直出错,一直无语 php-ffmpeg安装, tar文件安装也一直出错,一直无语 最后直接在系统上安装ffmpeg sudo a ...

  3. Win10激活KMS2.0

    目前,发现的唯一能激活Window10的纯净版. 下载地址: http://pan.baidu.com/s/1bpvMRBx 好孩子看不见: http://pan.baidu.com/s/1bo8xP ...

  4. Spring Boot 使用Jar打包发布, 并使用 Embedded Jetty/Tomcat 容器

    Jar包发布 在项目pom.xml中, 如果继承了Spring Boot的starter parent, 那么默认已经包含打包需要的plugins了, 设置为jar就能直接打包成包含依赖的可执行的ja ...

  5. Centos7.4和Ubuntu18.04安装PHP7.2

    安装依赖 yum install gcc-c++ libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcu ...

  6. Huginn部署到 Heroku

    折腾了几个小时,现在记录下安装步骤 1.本机Win10,放弃本地安装,官网建议也是, 2.安装虚拟机,装ubuntu系统 3.更换国内源(包括apt和gem,bunlde)ruby中国 4.注册her ...

  7. ios中图片旋转

    @interface ViewController () { UIImageView *_imageview; BOOL flag; } @end @implementation ViewContro ...

  8. ios中PagedFlowView的用法

    下载地址 引入PagedFlowView.h  PagedFlowView.m文件 #import <UIKit/UIKit.h> #import "PagedFlowView. ...

  9. ios 中手势用法

    pan拖动手势 - (void)viewDidLoad { [super viewDidLoad]; [self Pan]; // Do any additional setup after load ...

  10. 使用httpClient调用接口获取响应数据

    转自:https://blog.csdn.net/shuaishuaidewo/article/details/81136088 import lombok.extern.slf4j.Slf4j; i ...