uva 699

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
using namespace std;
const int maxn=1000000;
int sum[maxn];
void build(int p)
{
    int v;
    cin>>v;
    if(v==1)
    return;
    sum[p]+=v;
    build(p-1);
    build(p+1);
}
bool init()
{
    int v;
    cin>>v;
    if(v==1)
    return false;
    memset(sum,0,sizeof(sum));
    int pos=maxn/2;
    sum[pos]=v;
    build(pos-1);
    build(pos+1);
        return 0;
}
int main()
{
    freopen("p.in","r",stdin);
    freopen("p.out","w",stdout);
    int kase=0;
    while(init())
    {
        int p=0;
        while(sum[p]==0) p++;
        cout<<"Case"<<++kase<<":\n"<<sum[p++];
        while(sum[p]!=0) cout<<' '<<sum[p++];
        cout<<"\n\n";
    }
    return 0;
}

完美正确~~ 

好久以前的一道水题了,今天复习二叉树的时候写一遍吧

posted @ 2019-10-10 00:40  coolwx  阅读(116)  评论(0编辑  收藏  举报