杨辉三角
来源:互联网 发布:微商吸粉软件 编辑:程序博客网 时间:2024/05/20 05:54
杨辉三角
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 67572 Accepted Submission(s): 27943
Problem Description
还记得中学时候学过的杨辉三角吗?具体的定义这里不再描述,你可以参考以下的图形:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
Input
输入数据包含多个测试实例,每个测试实例的输入只包含一个正整数n(1<=n<=30),表示将要输出的杨辉三角的层数。
Output
对应于每一个输入,请输出相应层数的杨辉三角,每一层的整数之间用一个空格隔开,每一个杨辉三角后面加一个空行。
Sample Input
2 3
Sample Output
11 111 11 2 1
Author
lcy
Source
C语言程序设计练习(五)
Recommend
lcy | We have carefully selected several similar problems for you: 1000 2048 2046 1096 2049
#include<iostream>#include<cstdlib>#include<cstdio>#include<cmath>#include<cstring>#include<string>#include<cstdlib>#include <set>#include<algorithm>#include <limits.h>#include <ctype.h>#include <map>#include <stack>#include <sstream>typedef long long LL;using namespace std;const int N = 105;int data[N][N];int dp[N][N];char c[100][100] = {' '};#define PI 3.1415926void fun() { data[0][0] = 1; data[1][0] = 1; data[1][1] = 1; for(int i = 2; i <= 30; i++) { for(int j = 0; j <= i; j++) { if(j == 0 || j == i) data[i][j] = 1; else data[i][j] = data[i - 1][j - 1] + data[i - 1][j]; } }// for(int i = 0; i <= 30; i++){// for(int j = 0; j <= i; j++){// cout << data[i][j] << " ";// }// cout << endl;// }}int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int n; fun(); int flag = 0; while(scanf("%d", &n) != EOF) { //if(flag) cout << endl; for(int i = 0; i < n; i++) { for(int j = 0; j <= i; j++) { if(j == 0) cout << data[i][j] ; else cout << " "<< data[i][j] ; } cout << endl; } cout << endl; flag = 1; } return 0;}
0 0
- 杨辉三角/帕斯卡三角
- (尹成)杨辉三角(正三角 倒三角)
- 学习:杨辉三角(帕斯卡三角)
- 杨辉三角
- 杨辉三角
- 杨辉三角
- 杨辉三角算法
- C# 杨辉三角
- 杨辉三角
- 杨辉三角
- 杨辉三角程序
- 打印杨辉三角
- 杨辉三角
- 杨辉三角
- 杨辉三角
- 杨辉三角源代码
- 杨辉三角~~~~~~~~
- 杨辉三角
- 5、HotSpot的算法实现
- 标签中onclick绑定函数却is not defined的原因
- 斗地主-比较牌大小算法
- 自定义dialog
- 动态内存管理:模拟实现memcpy,memmove
- 杨辉三角
- CodeForces 5891 Lottery
- 在freecodecamp练习的算法题心得记录
- HDOJ 1914 The Stable Marriage Problem
- Android自定义View【实战教程】5⃣️---Canvas详解及代码绘制安卓机器人
- yande.re Y站API翻译
- 备忘录模式
- Box of Bricks
- RNN 的训练