POJ2255

来源:互联网 发布:数据库开发工程师招聘 编辑:程序博客网 时间:2024/05/22 00:38

这个遍历我觉的比我在网上看到的那些美感多了。。。。。

哈哈;

原理什么的还是看看百度吧;O.O

#include<iostream>#include<string.h>using namespace std;char pre[30],in[30];void revoer(int prel,int prer,int inl,int inr){if(prel<=prer&&inl<=inr){int i,root;for(root=0;root<=inr;root++){if(pre[prel]==in[root])break;}int leftsize=root-inl;int rightsize=inr-root;if(leftsize>0)revoer(prel+1,prel+leftsize,inl,root-1);if(rightsize>0)revoer(prer-rightsize+1,prer,root+1,inr);cout<<in[root];}}int main(){while(cin>>pre>>in){int prechang=strlen(pre);int inchang=strlen(in);        revoer(0,prechang-1,0,inchang-1);cout<<endl;}}


0 0
原创粉丝点击