简单题, 又是构造树而且不用存储的, 这种都不用实际地去构造一种struct,
直接递归然后计算即可,
这里像是一个边界不固定的数组, 下标有负数
所以我的思路是用一个map来记录每个pos的数量, 代码还是比较清晰, 就不多说了
话说用好递归真是事半功倍
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <cassert>
#include <iomanip>
using namespace std;
const int MAXN = 10005;
typedef long long LL;
/*
uva 699
*/
map<int,LL> Sum;
void drop(int pos){
int n;
cin >> n;
// cout << "pos=" << pos << ", n=" << n << endl;
if( n!=-1 ){
Sum[pos] += n;
drop(pos-1);
drop(pos+1);
}
}
int main(){
// freopen("input2.txt","r",stdin);
int n, Case = 0;
while( scanf("%d",&n)!=EOF && n!=-1 ){
Sum.clear();
Sum[0]+=n;
drop(-1);
drop(1);
map<int,LL>::iterator it = Sum.begin();
cout << "Case " << (++Case) << ":" << endl;
cout << it->second;
it++;
while( it!=Sum.end() ){
cout << " " << it->second;
it++;
}
cout << endl << endl;
}
return 0;
}