1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;
#define CLR(x,y) memset((x),(y),sizeof((x)))
const int maxn = 80 + 100;
int res[maxn];
void solve( int cur, int pos){
res[pos] += cur; //add weight to res
int lson,rson;
scanf ( "%d" ,&lson);
if (~lson) solve(lson,pos - 1); //lson
scanf ( "%d" ,&rson);
if (~rson) solve(rson,pos + 1); //rson
}
int ini(){
int v;
scanf ( "%d" ,&v);
if (v == -1) return 0; //the end of input
CLR(res,0);
solve(v,maxn/2);
return 1;
}
void show_res(){
int i = 0;
while (!res[i]) ++i;
printf ( "%d" ,res[i++]);
while (res[i])
printf ( " %d" ,res[i++]);
puts ( "\n" );
}
int main(){
int cntcase = 0;
while (ini()){
printf ( "Case %d:\n" ,++cntcase);
show_res();
}
return 0;
}
|