#include<stdio.h> #include<string.h> typedef struct Node{ int v; struct Node *left, *right; };//创建节点 Node * root; int count;//记录每个垂直同一条线的数位置 int a[250];//存储各个垂直数 Node *Buildtree(int n){ if(n == -1) return NULL;//判断是否有效 Node *t = new Node; t -> v = n; t -> left = t -> right = NULL; scanf("%d", &n); t -> left = Buildtree(n);//建立左儿子 scanf("%d", &n); t -> right = Buildtree(n);//建立右儿子 return t;//返回跟节点 }//递归建立二叉树 void DFS(Node *root, int count){ if(root == NULL) return; a[count] += root -> v;//每个同一条垂直线的数相加 DFS(root -> left, count - 1); DFS(root -> right, count + 1); }//深度遍历 int main(){ int p = 1, n, flag, i; while(1){ scanf("%d", &n); memset(a, 0, sizeof(a)); if(n == -1) break; root = Buildtree(n); DFS(root, 40);//40是取中间数,因为前后最多就+-5个 printf("Case %d:\n", p++); flag = 0; for(i = 0;i < 100; i++){ if(a[i]){ if(flag) printf(" "); flag = 1; printf("%d", a[i]); } } printf("\n"); printf("\n"); } return 0; }