CT/SWEA

[SWEA][D2][Python] 2005. 파스칼의 삼각형

hyunji1109 2023. 6. 14. 13:02

https://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

크기가 N인 파스칼의 삼각형을 만들어라.


 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
= int(input())
 
for tc in range(1, T+1):
    n = int(input())
 
    result = []
 
    for i in range(n):
        tmp = []
        for j in range(i+1):
            if j==0 or j==i:
                tmp.append(1)
            else:
                tmp.append(result[i-1][j]+result[i-1][j-1])
        result.append(tmp)
 
    print('#{}'.format(tc))
   for i in result:
        print(*i)
cs
 
print(i)출력시
[[1], [1, 1], [1, 2, 1]]
for i in result:
       print(*i) 출력시
1
11
121