zoukankan      html  css  js  c++  java
  • HDU 1515

    简单题,直接用STACK模拟整个过程。

    模拟出栈时,应注意保护现场,等到递归完成后返回。

     1 #include <iostream>
     2 #include <string.h>
     3 #include <cstdio>
     4 using namespace std;
     5 
     6 const int MAX=105;
     7 
     8 char ans[MAX*2];
     9 char s[MAX],t[MAX];
    10 int Stack[MAX];
    11 int lens,lent;
    12 void dfs(int sp,int tp,int top,int anst,int op){
    13     if(op==-1){
    14         ans[++anst]='o';
    15         top--;
    16         tp++;
    17     }
    18     else if(op==1){
    19         Stack[++top]=s[sp++];
    20         ans[++anst]='i';
    21     }
    22     if(sp>=lens){
    23         for(int i=top;i>=1;i--){
    24             if(Stack[i]==t[tp++])
    25             ans[++anst]='o';
    26             else return ;
    27         }
    28         for(int i=1;i<=anst;i++)
    29         printf("%c ",ans[i]);
    30         printf("
    ");
    31         return;
    32     }
    33     dfs(sp,tp,top,anst,1);
    34     if(Stack[top]==t[tp]&&top>0){
    35         char tmp=Stack[top];
    36         dfs(sp,tp,top,anst,-1);
    37         Stack[top]=tmp;
    38     }
    39 }
    40 
    41 int main(){
    42     while(cin>>s>>t){
    43         lens=strlen(s); lent=strlen(t);
    44         if(lens!=lent){
    45             printf("[
    ");
    46             printf("]
    ");
    47             continue;
    48         }
    49         printf("[
    ");
    50         dfs(0,0,0,0,0);
    51         printf("]
    ");
    52     }
    53 }
    View Code
  • 相关阅读:
    iOS开发UI篇—字典转模型
    使用python编写批量卸载android应用的脚本
    CircularProgressBar
    Custom-Progress-Dialog-Android
    picasso jar
    swift
    Python编程
    H264分析工具
    Android Websites
    AnATools
  • 原文地址:https://www.cnblogs.com/jie-dcai/p/3803422.html
Copyright © 2011-2022 走看看