#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <vector> #include <algorithm> #define N 100 using namespace std; int a[N*2]; void build(int value ,int w) { int n; a[w]+=value; scanf("%d",&n); if(n!=-1) build(n,w-1); scanf("%d",&n); if(n!=-1) build(n,w+1); } int main() { //freopen("ex.in","r",stdin); int n,ncase=0; while(scanf("%d",&n)&&n!=-1) { memset(a,0,sizeof(a)); build(n,N); int i=0; printf("Case %d:\n",++ncase); while(!a[i]) i++; printf("%d",a[i]); for(i++; a[i]; i++) printf(" %d",a[i]); printf("\n\n"); } return 0; }
699 - The Falling Leaves---递归
最新推荐文章于 2020-07-27 00:02:59 发布