博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVA 699 The Falling Leaves 数据结构
阅读量:6856 次
发布时间:2019-06-26

本文共 847 字,大约阅读时间需要 2 分钟。

  题目链接: UVA

  题目描述: 递归方式输入叶子节点权值, 输出每一列的叶子节点的权值之和

  解题思路: 还是递归输入和上题差不多。

  代码: 

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;const int maxn = 1e3+10;int sum[maxn];void build(int p) { int v; cin >> v; if(v == -1) return; sum[p] += v; build(p-1); build(p+1);}bool init() { int v; if((cin >> v)==EOF) return false; int pos = maxn >> 1; sum[pos] = v; build(pos-1); build(pos+1); return true;}int main() { freopen("in.txt", "r", stdin); while(init()) { int p = 0; while(sum[p]==0) p++; while(sum[p]!=0) { cout << sum[p++] << " "; } cout << endl; } return 0;}
View Code

  思考: 很烦, 这道题写很烦, 这样吧, 一会儿再写写面试题

转载于:https://www.cnblogs.com/FriskyPuppy/p/8027633.html

你可能感兴趣的文章
systemd (简体中文)
查看>>
CentOS5.5部署zlib导致yum使用不了,报错Yum Segmentation Fault (core Dumped)
查看>>
手把手安装配置 Syster Center Virtual Machiner(二)添加SCVMM主机
查看>>
我的友情链接
查看>>
charles的使用
查看>>
学习日志---python(新式类,面向对象)
查看>>
sersync+rsync实时同步配置案例
查看>>
第一章 面向系统架构的系统工程
查看>>
【学神】1-10 硬盘管理、文件系统及链接
查看>>
mvc与三层结构终极区别
查看>>
华为内部如何实施微服务架构?基本就靠这5大原则
查看>>
PC机声音图标为不可用(声音图标打叉)
查看>>
Lowest Common Ancestor of a Binary Tree Part
查看>>
ASP.NET 新增时多字段取值解决方案
查看>>
文字域替换
查看>>
springboot+vue的前后端分离与合并方案
查看>>
.net中使用存储过程output值和返回值
查看>>
2594. [WC2006]水管局长数据加强版【LCT+最小生成树】
查看>>
Day5-awk
查看>>
C++链式队列基本操作
查看>>