티스토리 뷰
2005. 파스칼의 삼각형
import java.util.Scanner;
// 210130
// 2005. 파스칼의 삼각형
public class SWEA2005 {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for (int tc = 1; tc <= T; tc++) {
int N = sc.nextInt();
int[][] arr = new int[N+1][N+1];
arr[1][1] = 1;
for(int i=2; i<=N; i++) {
for (int j=1; j<=i; j++) {
arr[i][j] = arr[i-1][j-1] + arr[i-1][j];
}
}
// 출력
System.out.println("#" + tc);
for(int i=1; i<=N; i++) {
for (int j=1; j<=i; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
} // for
sc.close();
} // main
}
'코딩테스트 > SW Expert' 카테고리의 다른 글
[SWEA] 1984. 중간 평균값 구하기 (0) | 2021.01.31 |
---|---|
[SWEA] 1986. 지그재그 숫자 (0) | 2021.01.31 |
[SWEA] 1989. 초심자의 회문 검사 (0) | 2021.01.30 |
[SWEA] 2001. 파리 퇴치 (0) | 2021.01.30 |
[SWEA] 1284. 수도 요금 경쟁 (0) | 2021.01.30 |
댓글