#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <stack>
#include <cctype>
#include <string>
#include <malloc.h>
#include <queue>
#include <map> using namespace std;
const int INF = 0xffffff;
const double Pi = * atan(); struct Node{
int val;
Node * right;
Node * left;
};
int cnt;
int a[];
int arr[];
int n,ll,rr;
void b_build(Node * &tmp){
if(n >= cnt)
return;
if(a[n] == -)
return;
tmp = new Node;
tmp->left = NULL;
tmp->right = NULL;
tmp->val = a[n];
if(n+ < cnt){
++n;
b_build(tmp->left);
}
if(n+ < cnt){
++n;
b_build(tmp->right);
}
} void dfs(Node * node,int num){
if(node == NULL)
return;
ll = min(ll,num);
rr = max(rr,num);
arr[num] += node->val;
dfs(node->left,num-);
dfs(node->right,num+);
return;
} int main()
{
// freopen("inpt.txt","r",stdin);
int cas = ;
while(){
int cntN = ;
int cntT = ;
int tmp;
cnt = ;
cin >> tmp;
if(tmp == -)
break;
a[cnt++] = tmp;
cntT++;
while(cin >> tmp){
if(tmp == -){
cntN++;
}
else{
cntT++;
}
a[cnt++] = tmp;
if(cntN == cntT + )
break;
}
Node * root = NULL;
n = ;
b_build(root);
memset(arr,,sizeof(arr));
ll = ;
rr = ;
dfs(root,);
cout << "Case " << ++cas << ":" << endl;
for(int i = ll;i < rr;i++)
cout << arr[i] << ' ';
cout << arr[rr] << endl;
cout << endl;
}
return ;
}
uva699 前序遍历建树然后dfs深搜用数组标记偏移……2333333
很简单的水题,数组开小了,一直wa……!