UVA 699(p159)----The Falling Leaves

1084 단어
4
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define debu
using namespace std;
const int maxn=1e3;
int sum[maxn];
void build(int p)
{
    int x;
    scanf("%d",&x);
    if(x==-1) return ;
    sum[p]+=x;
    build(p-1);
    build(p+1);
}
int main()
{
#ifdef debug
    freopen("in.in","r",stdin);
    freopen("out.out","w",stdout);
#endif // debug
    int x,cas=0;
    while(scanf("%d",&x))
    {
        if(x==-1) break;
        memset(sum,0,sizeof(sum));
        int pos=maxn/2;
        sum[pos]=x;
        build(pos-1);
        build(pos+1);
        int tmp=0;
        while(!sum[tmp]) tmp++;
        printf("Case %d:
%d",++cas,sum[tmp++]); while(sum[tmp]) { printf(" %d",sum[tmp]); tmp++; } printf("

"); } return 0; }
제목 주소:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=640

좋은 웹페이지 즐겨찾기