SWEA 2005 파스칼의 삼각형

Jmnote (토론 | 기여)님의 2019년 1월 24일 (목) 22:22 판

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++) {
            System.out.format("#%d\n", t);
            int n = sc.nextInt();
            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]);
                System.out.println();
                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];
            }
        }
    }
}

4 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}