http://acm.hdu.edu.cn/showproblem.php?pid=1515 #include<iostream> using namespace std; #include<string.h> int len1,len2; char stack[200]; char s1[200],s2[200]; char ans[200]; void dfs(int cur,int top,int idx,int step) { int i,t; char tmp; if(idx==len2) { for(i=0;i<step;i++) printf("%c ",ans[i]); cout<<endl; return; } if(cur<len1) { t=top+1; tmp=stack[t];//?? stack[t]=s1[cur]; ans[step]='i'; dfs(cur+1,t,idx,step+1); stack[t]=tmp; //??? } if(top==-1) return; if(s2[idx]==stack[top]) { t=top-1; ans[step]='o'; dfs(cur,t,idx+1,step+1); } return; } int main() { while(scanf("%s%s",s1,s2)!=EOF) { len1=strlen(s1); len2=strlen(s2); if(len1<len2) { printf("[/n]/n"); continue; } puts("["); dfs(0,-1,0,0); puts("]"); } return 0; } ??的地方想不明白。。明明不需要恢复栈中的元素。。