zoukankan      html  css  js  c++  java
  • ZOJ(1004)Anagrams by Stack (DFS+stack)

    #include <iostream>
    #include <stdio.h>
    #include <string>
    #include <string.h>
    #include <algorithm>
    #include <math.h>
    #include <fstream>
    #include <vector>
    #include <map>
    #include <queue>
    #include <stack>
    #include <math.h>
    #include <stdlib.h>
    using namespace std ;
    string origion,target;
    stack<char>build;
    vector<char>operate;
    int length;
    void dfs(int ipush,int ipop){
        if(ipush == length&&ipop == length){
            for(int i = 0;i < operate.size();i++)
                cout<<operate[i]<<" ";
            cout<<endl;
        }
        if(ipush+1<=length){
            build.push(origion[ipush]);
            operate.push_back('i');
            dfs(ipush+1,ipop);
            build.pop();
            operate.pop_back();
        }
        if(ipop+1 <= ipush && ipop+1 <= length && build.top() == target[ipop]){
            char temp = build.top();
            build.pop();
            operate.push_back('o');
            dfs(ipush,ipop+1);
            build.push(temp);
            operate.pop_back();
        }
    }
    int main(){
        while(cin>>origion>>target){
            length = origion.size();
            cout<<"["<<endl;
            dfs(0,0);
            cout<<"]"<<endl;
        }
        return 0 ;
    }
  • 相关阅读:
    hbase与Hive的集成
    HBase API操作
    HBase原理
    HBase数据结构
    HBase Shell操作
    HBase简介
    Boxes in a Line
    B
    B. Painting Pebbles
    X
  • 原文地址:https://www.cnblogs.com/Roly/p/3064832.html
Copyright © 2011-2022 走看看