随笔-68  评论-10  文章-0  trackbacks-0
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=104&page=show_problem&problem=640
#include <iostream>
#include 
<cstring>
using namespace std;
const int maxn = 205;
int leaf[maxn];

void proc_tree(int idx)
{
    
int t;
    cin 
>> t;
    
if(t != -1)
    
{
        leaf[idx 
- 1+= t;
        proc_tree(idx 
- 1);
    }

    cin 
>> t;
    
if(t != -1)
    
{
        leaf[idx 
+ 1+= t;
        proc_tree((idx 
+ 1));
    }

}


int main()
{
    
int h, ca = 0;
    
while(cin >> h && h != -1)
    
{
        memset(leaf, 
0sizeof(leaf));
        
int mid = maxn / 2;
        leaf[mid] 
+= h;
        proc_tree(mid);
        cout 
<< "Case " << ++ca << ':' << endl;
        
for(int i = 0; i < maxn - 1++i)
        
if(leaf[i])
        
{
            cout 
<< leaf[i];
            
if(leaf[i + 1]) cout << ' ';
        }

        cout 
<< endl << endl;
    }

    
return 0;
}


posted on 2011-11-29 16:42 wuxu 阅读(370) 评论(0)  编辑 收藏 引用 所属分类: 数据结构

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理