HDU 2032 杨辉三角
2015-07-19 16:25
204 查看
Description
还记得中学时候学过的杨辉三角吗?具体的定义这里不再描述,你可以参考以下的图形:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
[b]Input
[/b]
输入数据包含多个测试实例,每个测试实例的输入只包含一个正整数n(1<=n<=30),表示将要输出的杨辉三角的层数。
[b]Output
[/b]
对应于每一个输入,请输出相应层数的杨辉三角,每一层的整数之间用一个空格隔开,每一个杨辉三角后面加一个空行。
[b]Sample
Input
[/b]
2
3
[b]Sample
Output
[/b]
1
1
1
1
1
1
1
2 1
代码:
还记得中学时候学过的杨辉三角吗?具体的定义这里不再描述,你可以参考以下的图形:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
[b]Input
[/b]
输入数据包含多个测试实例,每个测试实例的输入只包含一个正整数n(1<=n<=30),表示将要输出的杨辉三角的层数。
[b]Output
[/b]
对应于每一个输入,请输出相应层数的杨辉三角,每一层的整数之间用一个空格隔开,每一个杨辉三角后面加一个空行。
[b]Sample
Input
[/b]
2
3
[b]Sample
Output
[/b]
1
1
1
1
1
1
1
2 1
代码:
#include<stdio.h> #include<cstring> #define N 100 using namespace std; int main() { int t,c[N][N]; while(~scanf("%d",&t)) { memset(c,0,sizeof(c)); for(int i=0; i<t; i++) { c[i][0]=1; int k=i+1; for(int j=1; j<=t; j++) { c[k][j]=c[k-1][j-1]+c[k-1][j]; } } for(int i=0; i<t; i++) { for(int j=0; j<t; j++) { if(c[i][j]==0)break; else if(i == j) printf("%d\n",c[i][j]); //这有坑》》最后一个数后面没空格 else printf("%d ",c[i][j]); } } printf("\n"); } return 0; }
相关文章推荐
- 交换两个变量的不同实现方式
- MongoDB初探系列之三:MongoDB用户权限操作
- Latch-Learned Arrangements of Three Patch Codes (1)
- 业务串讲
- 中文转为unicode编码
- 计算客 商品推荐走马灯(简单)(求区间所有连续的回文串价值)
- 用纯CSS实现的箭头
- RESTFUL接口
- webservice xml soap wsdl 必要知识
- 栈和堆
- 正则表达式中各种字符的含义
- SQL脚本积累之六-----游标的使用示例
- Python学习-centos7.0下matplotlib安装及问题解决
- 正则表达式中各种字符的含义
- 动态获取页面参数内容
- java语言复制二进制流数据
- HDU 1272 无聊神坑并查集
- springmvc解析器使用总结
- ubuntu下配置vim插件时注意事项
- KAZE 特征笔记