699 - The Falling Leaves

 1 #include<iostream>
 2 using namespace std;
 3 int result[161];
 4 int count=1;
 5 struct node{
 6     int horizon;
 7     int value;
 8     node* lchild;
 9     node* rchild;
10 };
11 node* build(int horizon)
12 {
13     int value;
14     cin>>value;
15     if(value==-1)
16      return NULL;
17     else
18     {
19         node *p=new node;
20         p->value=value;
21         p->horizon=horizon;
22         result[horizon]+=value;
23         p->lchild=build(horizon-1);
24         p->rchild=build(horizon+1);
25         return p;
26     }
27 }
28 int main()
29 {
30     while(1)
31     {
32         int i;
33         for(i=0;i<161;i++)
34             result[i]=0;
35          build(80);
36          int total=0;
37          for(i=0;i<161;i++)
38            if(result[i])
39                total++;
40            if(!total)
41                break;
42          cout<<"Case "<<count++<<":"<<endl;
43          for(i=0;i<161;i++)
44              if(result[i])
45              {
46                  cout<<result[i];
47                  total--;
48                  if(total!=0)
49                      cout<<" ";
50              }
51              cout<<endl;
52              cout<<endl;
53     }
54     return 0;
55 }
56         

 

  

posted @ 2013-03-31 00:08  sooflow  阅读(155)  评论(0)    收藏  举报