ZJU ACM 1004
来源:互联网 发布:ie浏览器不能登录淘宝 编辑:程序博客网 时间:2024/05/20 22:02
/** ZOJ-1004 Anagrams By Stack
http://acm.zju.edu.cn/show_problem.php?pid=1004
Yimin.Li
**/
#include <iostream>
#include <stack>
#include <vector>
#include <string>
using namespace std;
class AnagramsByStack
{
private:
vector<char> track; // "i"¡¢"o"¹ì¼£
int idxSource, idxDest; // Ô´×Ö·û´®¡¢Ä¿±ê×Ö·û´® Ë÷Òý
string strSource, strDest; // Ô´×Ö·û´®¡¢Ä¿±ê×Ö·û´®
int strLen; // ×Ö·û´®³¤¶È
public:
static stack<char> charStk; // ²Ù×÷Õ»
public:
void initialize(const string &strSource,
const string &strDest)
{
this->strSource = strSource;
this->strDest = strDest;
idxSource = 0;
idxDest = 0;
strLen = strSource.length();
}
void execute()
{
if( idxDest>=strLen )
{
vector<char>::iterator iter;
for(iter=track.begin(); iter!=track.end(); ++iter)
{
cout << *iter << ' ';
}
cout << endl;
return ;
}
if( idxSource<strLen )
{
charStk.push(strSource[idxSource++]);
track.push_back('i');
execute();
charStk.pop();
track.pop_back();
--idxSource;
}
if( !charStk.empty() )
{
char ch = charStk.top();
if( strDest[idxDest]==ch )
{
charStk.pop();
track.push_back('o');
++idxDest;
execute();
--idxDest;
track.pop_back();
charStk.push(ch);
}
}
return ;
}
};
stack<char> AnagramsByStack::charStk;
int main()
{
string strSource, strDest;
AnagramsByStack app;
while(cin>>strSource>>strDest)
{
cout << "[/n" ;
if ( strSource.length()==strDest.length() )
{
app.initialize(strSource, strDest);
app.execute();
}
cout << "]/n" ;
}
return 0;
}
- ZJU ACM 1004
- zju acm 1622
- acm zju 1712
- ZJU ACM 1005
- zju acm 1007
- acm zju 1698
- ACM ZJU 2104
- ACM ZJU 1808
- CAPTCHA zju 校赛 acm
- acm.zju.3507
- acm.zju.1586
- ACM zju 1003 源代码(参考)
- Jug 倒水问题 ZJU ACM
- zju 1004 zoj 1004
- ZJU PAT 1004
- ACM大数的高精度模板一套,来自zju
- 第一个zju的acm程序(ID:1001)
- ZJU 1004 Anagrams by Stack
- utf编码在线转换工具
- 访谈:微软PowerShell 2.0中的新特性
- Struts(JFIS)
- 1.6 [Enterprise Libary ] 使用不同的程序集
- 什么是Ajax?
- ZJU ACM 1004
- ORACLE 常用的SQL语法和数据对象
- 读取excel文件
- OA从domino5升级到domino7时的语言问题
- MySQL:昨天的"玩具"到今天的竞争者
- ZJU ACM 1005
- 在Windows下通过JConfig获取磁盘剩余空间信息
- [转]LDO资料
- 用CSS实现文字的自动隐藏 并且出现三点