当前位置: 代码迷 >> 综合 >> HDU 2032
  详细解决方案

HDU 2032

热度:78   发布时间:2023-12-15 11:52:13.0

不知道为什么,自己写的就会一直错,大佬的就ac

大佬的:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>int main()
{int n,i,j,s,sum;int a[50][50]={
   {1},{1,1}};while(scanf("%d",&n)!=EOF){for(i=2;i<n;i++){a[i][0]=1;a[i][i]=1;for(j=1;j<i;j++){a[i][j]=a[i-1][j-1]+a[i-1][j];}}for(i=0;i<n;i++){for(j=0;j<=i;j++){if(j==i)printf("%d",a[i][j]);else printf("%d ",a[i][j]);}printf("\n");}printf("\n");}return 0;
}

自己的:

#include<stdio.h>
#include <malloc.h>
#define  N 30
int a[N][N]={0};
void yanghui(int n){for(int i=0;i<n;i++){for(int j=0;j<=i;j++){a[i][j] = 0;}}for(int i=0;i<n;i++){for(int j=0;j<=i;j++){if(j==0 || i==j){a[i][j] = 1;}else{a[i][j] = a[i-1][j] + a[i-1][j-1];}if(j==i){printf("%d",a[i][j]);}else{printf("%d ",a[i][j]);}}printf("\n");}
}
int main() {//int N = 10;int tmp = 0;int d= 0;while(scanf("%d",&tmp) != EOF){d++;if(d != 1){printf("\n");}yanghui(tmp);}//yanghui(2);//yanghui(3);/*int a[N][N] = {0};for(int i=0;i<N;i++){for(int j=0;j<=i;j++){if(j==0 || j== i) {a[i][j] = 1;}else{a[i][j] = a[i-1][j] + a[i-1][j-1];}printf("%d ",a[i][j]);}printf("\n");}*/return 0;
}