无需建树,递归写入数组,然后就是答案输出。
#include <cstdio>
#include <cstring>
#define MAXN 1001
int rst[MAXN], val;
void recusion_set_rst(const int &idx)
{
scanf("%d", &val);
if( -1 != val ) {
rst[idx-1] += val;
recusion_set_rst(idx-1);
}
scanf("%d", &val);
if( -1 != val ) {
rst[idx+1] += val;
recusion_set_rst(idx+1);
}
}
int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
freopen("test.in", "r", stdin);
#endif
int cas(1), idx;
while( scanf("%d", &val) && (-1 != val) ) {
memset(rst, 0, sizeof(rst));
idx = MAXN>>1; rst[idx] += val;
recusion_set_rst(idx);
printf("Case %d:\n", cas ++); idx = 0;
for(int i = 0; i < MAXN; i ++) {
if( !rst[i] ) {
continue;
}
if( idx ) {
printf(" ");
}
else {
idx = 1;
}
printf("%d", rst[i]);
}
printf("\n\n");
}
return 0;
}
uva_699_The Falling Leaves
最新推荐文章于 2022-08-31 13:36:30 发布