UVA_699
模拟题目所说的即可。
#include<stdio.h>
#include<string.h>
#define MAXD 160
#define MID 80
int first, f[MAXD];
void dfs(int cur)
{
int k;
scanf("%d", &k);
if(k == -1)
return ;
if(f[cur] == -1)
f[cur] = k;
else
f[cur] += k;
dfs(cur - 1);
dfs(cur + 1);
}
void solve()
{
int i;
memset(f, -1, sizeof(f));
f[MID] = first;
dfs(MID - 1);
dfs(MID + 1);
for(i = 0; f[i] == -1; i ++);
printf("%d", f[i ++]);
for(; f[i] != -1; i ++)
printf(" %d", f[i]);
printf("\n");
}
int main()
{
int t = 0;
for(;;)
{
scanf("%d", &first);
if(first == -1)
break;
printf("Case %d:\n", ++ t);
solve();
printf("\n");
}
return 0;
}