uva 699
2015-05-20 11:54
232 查看
用一个int 变量 p 记录一下树中节点的位置,边输入就可以建树。
用flag 变量记录是否初始化。
用flag 变量记录是否初始化。
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> using namespace std; const int maxn = 10000; int tree[maxn]; bool flag = true; bool input(int p){ int n; cin>>n; if(n==-1) return false; if(flag == true){ memset(tree,0,sizeof(tree)); tree[p] = n; flag = false; } else { tree[p] += n; } input(p-1);input(p+1); return true; } int main(){ int kase = 0; while(input(maxn/2)){ int p = 0; while(tree[p] == 0) p++; cout<<"Case "<<++kase <<":\n"<<tree[p++]; while(tree[p] != 0) cout<<" "<<tree[p++]; cout<<"\n\n"; flag = true; } return 0; }
相关文章推荐
- 下落的树叶(UVa 699)
- UVA 699 The Falling Leaves
- Uva-699 - The Falling Leaves(二叉树与递归)
- UVA.699 The Falling Leaves (二叉树 思维题)
- 例题6-10 下落的树叶(The Falling Leaves, UVa 699)
- uva 699 The Falling Leaves(建二叉树同一时候求和)
- uva 699 The Falling Leaves
- UVa 699 落叶
- UVA - 699 The Falling Leaves
- The Falling Leaves UVA - 699
- uva 699 The Falling Leaves(建树)
- UVA 699 - The Falling Leaves
- UVA699 - The Falling Leaves
- uva_699_The Falling Leaves
- UVA 699 二叉树结合数组求求解点的值
- UVA 699 - The Falling Leaves
- UVa699-The Falling Leaves(下落的叶子)
- uva 699
- UVA - 699 The Falling Leaves
- UVA 699 The Falling Leaves