给了二叉树的先序遍历给成后续遍历。。
解题: 分而治之。。
View Code
#include<iostream> #include<string.h> #include<algorithm> #include<stdio.h> using namespace std; const int maxn=100000; int number[maxn]; void solve(int s,int e) { if(s==e) {cout<<number[s]<<endl;return ;} int i=s; for( i=s+1;i<=e;i++) if(number[i]>number[s]) break; if(s+1<=i-1)solve(s+1,i-1); if(i<=e)solve(i,e); cout<<number[s]<<endl; } int main() { int i=-1; while(scanf("%d",&number[++i])!=EOF); solve(0,i-1); return 0; }