【算法】程序猿不写代码是不对的65
来源:互联网 发布:卖家怎样开通淘宝达人 编辑:程序博客网 时间:2024/06/03 18:35
package com.kingdz.algorithm.time201706;import java.util.ArrayList;import java.util.List;/** * <pre> * 数字金字塔 * 6 * 7 3 * 2 9 4 * 3 5 1 8 * 6 2 7 7 4 * 如上的金字塔形状,从最上面的数字向下走,只能选相邻近的数字,不能跨行或跨列,保证到达最下面时经过的数字和最大 * </pre> * * @author kingdz * */public class Algo02 { public static void main(String[] args) { List<String> list = new ArrayList<String>(); list.add("6"); list.add("7 3"); list.add("2 9 4"); list.add("3 5 1 8"); list.add("6 2 7 7 4"); int[][] tower = new int[list.get(list.size() - 1).split(" ").length][list.size()]; // 根据输入构建二维数组 int i = 0; for (String str : list) { String[] array = str.split(" "); int j = 0; for (String tmp : array) { tower[i][j] = Integer.parseInt(tmp); j++; } i++; } // 进行计算求出最大值 int y = 0; int sum = tower[0][y]; for (int x = 1; x < tower.length; x++) { if (tower[x][y] > tower[x][y + 1]) { sum = sum + tower[x][y]; } else { sum = sum + tower[x][y + 1]; y = y + 1; } } System.out.println(sum); }}
阅读全文
0 0
- 【算法】程序猿不写代码是不对的65
- 【算法】程序猿不写代码是不对的1
- 【算法】程序猿不写代码是不对的2
- 【算法】程序猿不写代码是不对的3
- 【算法】程序猿不写代码是不对的4
- 【算法】程序猿不写代码是不对的5
- 【算法】程序猿不写代码是不对的6
- 【算法】程序猿不写代码是不对的7
- 【算法】程序猿不写代码是不对的8
- 【算法】程序猿不写代码是不对的9
- 【算法】程序猿不写代码是不对的10
- 【算法】程序猿不写代码是不对的11
- 【算法】程序猿不写代码是不对的12
- 【算法】程序猿不写代码是不对的13
- 【算法】程序猿不写代码是不对的14
- 【算法】程序猿不写代码是不对的15
- 【算法】程序猿不写代码是不对的16
- 【算法】程序猿不写代码是不对的17
- git clone时,提示warning: remote HEAD refers to nonexistent ref, unable to checkout.
- 笔记:接着前面的来,清空listview,刷新音乐列表
- [bigdata-088] go+ubuntu 一个最简单的api返回json格式数据的web app
- IPC之---管道
- 欢迎使用CSDN-markdown编辑器
- 【算法】程序猿不写代码是不对的65
- java 校验文件头 判断虚假文件
- CSU--------2133: 中南大学2017年ACM暑期集训前期训练题集(基础题)
- python013 -- 常用标准库
- Sql语句中使用自定义变量
- js jquery 判断对象是否为空
- 提示Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp;
- Python基础语法--一些例子
- 深入NSTimer(iOS)