#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <iostream>
using namespace std;
const int maxn=300;
int sum[maxn];
void build(int p){
int v;cin>>v;
if(v==-1)return;
sum[p]+=v;
build(p-1);build(p+1); //这一步模拟了前序遍历
}
bool solve(){
int v;cin>>v;
if(v==-1) return false;
memset(sum,0,sizeof(sum));
int pos=maxn/2;
sum[pos]=v;
build(pos-1);build(pos+1);
return true;
}
int main(){
string line;
while(solve()){
int p=0;
while(sum[p]==0)p++;
while(sum[p]!=0)cout<<" "<<sum[p++];
cout<<"\n";
}
return 0;
}
uva-699
最新推荐文章于 2024-04-11 16:23:11 发布