题意:
看白书
要点:
构造一个数组,从中间的下标开始,向左就-1,向右就+1,够简单的
#include#include #include #define maxn 100005int sum[maxn];bool build(int p){ int v; scanf("%d", &v); if (v == -1) return false; sum[p] += v; build(p - 1); build(p + 1); return true;}int main(){ int kase = 0; while (build(maxn / 2)) { int p = 0; while (sum[p] == 0) p++; printf("Case %d:\n%d", ++kase,sum[p++]); while (sum[p] != 0) printf(" %d", sum[p++]); printf("\n\n"); memset(sum, 0, sizeof(sum)); } return 0;}