码迷,mamicode.com
首页 > 其他好文 > 详细

6-10 下落的树叶 uva699

时间:2019-01-19 12:21:47      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:void   水平   c++   open   root   ide   eof   color   names   

类似第九题  都是属于比较巧妙的题目  !

 

用一个p数组来保存水平值   然后开始built  

自然就会按照自左而右的顺序来读取!!!!!!这很重要

 

技术分享图片
#include<bits/stdc++.h>
using namespace  std;
void  built (int pos);

int p[10000]={0};
int main()
{

    int root;int cas=0;
    while(cin>>root&&root!=-1)
    {   memset(p,0,sizeof(p));

      p[1000]+=root;
      built(1000-1);built(1000+1);


       int t=0;
        while(p[t]==0)t++;
        printf("Case %d:\n",++cas);
        printf("%d",p[t]);
        while(p[++t]!=0) printf(" %d",p[t]);

       cout<<endl<<endl;
    }

    return 0;
}

void  built (int pos)
{   int n;
    cin>>n;
    if(n==-1)  return ;
    p[pos]+=n;

    built(pos-1);built(pos+1);
}
View Code

 

6-10 下落的树叶 uva699

标签:void   水平   c++   open   root   ide   eof   color   names   

原文地址:https://www.cnblogs.com/bxd123/p/10290901.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!