UVA699 下落的树叶 The Falling Leaves
bool型的函数一定不能忘了组后要加上return 1;或者return 0;!!!!
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout<<"# "<<x<<" "<<endl;
typedef long long ll;
const ll mod=2147483647;
const ll N=1e4+7;
ll sum[N],n,cnt;
inline void build(ll p)
{//先序遍历
ll v;
cin>>v;
if(v==-1)return ;//空就返回==if(t.val==NULL)return ;
sum[p]+=v;
build(p-1);//先左
build(p+1);//后右
}
inline bool init()
{
ll v;
cin>>v;
if(v==-1)return false;
memset(sum,0,sizeof sum);
ll pos=N/2;
sum[pos]=v;
build(pos-1);
build(pos+1);
return 1;//bool型的函数一定不能忘了组后要加上return 1;或者return 0;QWQ刘汝佳坑我
}
int main()
{
while(init())
{
ll p=0;
while(sum[p]==0)p++;//先找到最左边的子节点
cout<<"Case "<<++cnt<<":\n"<<sum[p++];
while(sum[p])cout<<" "<<sum[p++];
cout<<"\n\n";
}
return 0;
}
有任何疑问欢迎评论哦虽然我也很菜