티스토리 뷰

2005. 파스칼의 삼각형

swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=2&contestProbId=AV5P0-h6Ak4DFAUq&categoryId=AV5P0-h6Ak4DFAUq&categoryType=CODE&problemTitle=&orderBy=FIRST_REG_DATETIME&selectCodeLang=ALL&select-1=2&pageSize=10&pageIndex=1

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

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
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
글 보관함