1089: 杨辉三角
来源:互联网 发布:古生物学与地层学知乎 编辑:程序博客网 时间:2024/06/08 16:47
网址:http://begin.lydsy.com/JudgeOnline/problem.php?id=1089
1089: 杨辉三角
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 480 Solved: 176
[Submit][Status][Web Board]
Description
输出杨辉三角的前N行(N<10)。
Input
输入只有一行,包括1个整数N。(N<10)
Output
输出只有N行,每行输出的数字间用一个空格分开,最后一个数字后面没有空格。
Sample Input
5
Sample Output
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
HINT
Source
AC代码:
package 杨辉三角0089;
import java.util.Scanner;
public class Main {
public static void main(String[] args) { Scanner in = new Scanner(System.in); int lines = in.nextInt(); printYFTriangle(lines);}public static void printYFTriangle(int lines){ int[] a = new int[lines + 1]; int previous = 1; for (int i = 1; i <= lines; i ++){ for (int j = 1; j <= i; j++){ int current = a[j]; a[j] = previous + current; previous = current; if (j == i) { System.out.print(a[j]); } else { System.out.print(a[j] + " "); } } System.out.println(); }}
}
阅读全文
0 0
- 1089: 杨辉三角
- 杨辉三角/帕斯卡三角
- 【HUSTOJ】1089: 杨辉三角
- (尹成)杨辉三角(正三角 倒三角)
- 学习:杨辉三角(帕斯卡三角)
- 杨辉三角
- 杨辉三角
- 杨辉三角
- 杨辉三角算法
- C# 杨辉三角
- 杨辉三角
- 杨辉三角
- 杨辉三角程序
- 打印杨辉三角
- 杨辉三角
- 杨辉三角
- 杨辉三角
- 杨辉三角源代码
- 自定义注释几个参数说明
- 微信小程序 录音文件格式silk 坑
- 时间模型类TimestampBehavior
- 【转】采购订单长文本增强
- Android 头像修改
- 1089: 杨辉三角
- 有用的性能指标
- java
- 1090: 螺旋方阵
- transform基本转换应用2D
- 数据结构-栈
- Spring10---spring整合JDBC_02_基于RowMapper的查询
- 19:简单计算器
- mysql客户端操作需要显示或输入中文时出现乱码——解决办法