ZOJ Problem Set - 1004-Anagrams by Stack
唉!先直接上源码吧!什么时候有时间的再来加说明。
#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的更多相关文章
- [ZJU 1004] Anagrams by Stack
ZOJ Problem Set - 1004 Anagrams by Stack Time Limit: 2 Seconds Memory Limit: 65536 KB How can a ...
- stack+DFS ZOJ 1004 Anagrams by Stack
题目传送门 /* stack 容器的应用: 要求字典序升序输出,所以先搜索入栈的 然后逐个判断是否满足答案,若不满足,回溯继续搜索,输出所有符合的结果 */ #include <cstdio&g ...
- ZOJ 1004 Anagrams by Stack
Anagrams by Stack 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1004 题意:通过堆栈实现将一 ...
- ZOJ 1004 Anagrams by Stack(DFS+数据结构)
Anagrams by Stack 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4 题目大意:输入两个字符串序列,判 ...
- [ZOJ 1004] Anagrams by Stack (简单搜索)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1004 题目大意:给你个栈,给你源串和目标串,按字典序输出符合要求 ...
- ZOJ Problem Set - 1004
1.翻译参考 http://liucw.blog.51cto.com/6751239/1198026 2.代码参考 http://www.cnblogs.com/devymex/archive/201 ...
- 1004 Anagrams by Stack
考察DFS的应用,用栈描述字符串的变化过程. #include <stdio.h> #include <string.h> int len1,len2; ],str2[],st ...
- Anagrams by Stack(深度优先搜索)
ZOJ Problem Set - 1004 Anagrams by Stack Time Limit: 2 Seconds Memory Limit: 65536 KB How can a ...
- HDU ACM 1515 Anagrams by Stack
Anagrams by Stack Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
随机推荐
- 〖Android〗利用droidsshd在Android手机中开启 sshd,sftp,..
源码下载地址: src: git clone https://code.google.com/p/droidsshd/ apk: http://droidsshd.googlecode.com/fil ...
- 微软Xbox One无线手柄控制机器人
ROS中的joy包提供了游戏手柄的驱动,并且包含joy_node节点,这一节点可以发布包含手柄按钮和轴信息的Joy消息.在终端中输入下面命令,安装joy包: $ sudo apt-get instal ...
- Aggressive cows
总时间限制: 1000ms 内存限制: 65536kB 描述 Farmer John has built a new long barn, with N (2 <= N <= 100,00 ...
- ArcGIS10.1正式版全套下载、安装与破解(附ArcGIS10.1全套下载地址)【转】
一.准备文件1.ArcGIS10.1安装包:ArcGIS_Desktop_10.1_129026(en)2.认证服务:Pre-release_license_manager3.注册机:arcgis10 ...
- linux c server and client 简单的通信
server.c #include <stdlib.h> #include <stdio.h> #include <errno.h> #include <st ...
- A. Kyoya and Photobooks(Codeforces Round #309 (Div. 2))
A. Kyoya and Photobooks Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He ...
- 【Oracle+PHP】php连接oracle设定字符集,避免乱码
数据库用oracle,当php连接oracle的时候,最好指定字符集. 查PHP手册,oci_connect的第四个参数为charset,这是关键. 首先获取oracle的字符集,运行“select ...
- BigDecimal去除末尾多余的0
Java有自带的 stripTrailingZeros() 方法用于去除末尾多余的0 BigDecimal num = new BigDecimal("100.000"); Big ...
- [转] 利用BLKTRACE分析IO性能
在Linux系统上,如果I/O发生性能问题,有没有办法进一步定位故障位置呢?iostat等最常用的工具肯定是指望不上的,[容易被误读的iostat]一文中解释过await表示单个I/O所需的平均时间, ...
- librbd 分析
一.概述