SWEA 2005 파스칼의 삼각형

Jmnote (토론 | 기여)님의 2018년 9월 7일 (금) 22:01 판 (→‎개요)

1 개요

SWEA 2005 파스칼의 삼각형
SW Expert 아카데미
# 문제 풀이

틀:SWEA 난이도 2-1

2 C++

3 Java

import java.util.Scanner;
class Solution {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        for(int t=1; t<=T; t++) {
            int n = sc.nextInt();
            System.out.format("#%d\n", t);
            int cur[] = new int[n+2];
            int next[] = new int[n+2];
            cur[1] = 1;
            int i, j;
            for(i=1; i<=n; i++) {
                for(j=1; j<i+1; j++) System.out.format("%d ", cur[j]);
                for(j=1; j<i+2; j++) next[j] = cur[j-1]+cur[j];
                for(j=1; j<i+2; j++) cur[j] = next[j];
                System.out.println();
            }
        }
    }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}