반응형
문제 이해
아이디어
코드
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = Integer.parseInt(sc.nextLine());
for (int tc = 1; tc <= T; ++tc) {
int N = Integer.parseInt(sc.nextLine());
int[][] pascal = new int[N][N];
int cnt = 1;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < cnt; ++j) {
if (j == 0 || j == cnt - 1)
pascal[i][j] = 1;
else {
pascal[i][j] = pascal[i - 1][j - 1] + pascal[i - 1][j];
}
}
cnt++;
}
System.out.println("#" + tc + " ");
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
if (pascal[i][j] != 0)
System.out.print(pascal[i][j] + " ");
}
System.out.println();
}
}
sc.close();
}
}
집사는개발자가되고파
choppadontbiteme.tistory.com
반응형
'Algorithm > SWEA' 카테고리의 다른 글
[SWEA] 1926. 간단한 369 게임 D2 JAVA (0) | 2021.03.26 |
---|---|
[SWEA] 2007. 패턴 마디의 길이 D2 JAVA (0) | 2021.03.26 |
[SWEA] 1989.초심자의 회문 검사 D2 JAVA (0) | 2021.03.26 |
[SWEA] 1986. 지그재그 숫자 D2 JAVA (0) | 2021.03.26 |
[SWEA] 1984. 중간 평균값 구하기 D2 JAVA (0) | 2021.03.26 |