uva 699 The Falling Leaves
https://vjudge.net/problem/UVA-699
#include<cstdio> #include<cstring> #define N 80; using namespace std; int sum[200]; void dfs(int pos) { int rt; scanf("%d",&rt); if(rt==-1) return; sum[pos]+=rt; dfs(pos-1); dfs(pos+1); } bool read() { int rt,pos=N; scanf("%d",&rt); if(rt==-1) return false; memset(sum,0,sizeof(sum)); sum[pos]=rt; dfs(pos-1); dfs(pos+1); return true; } int main() { int T=0; while(1) { if(!read()) return 0; printf("Case %d:\n",++T); int i=1; for(i=1;i<200;i++) if(sum[i]) break; printf("%d",sum[i]); for(int j=i+1;sum[j];j++) printf(" %d",sum[j]); printf("\n\n"); } }