α׷

 3206, 2/161 ȸ  α  
   sunnykim97
   ̽: ĽĮ ﰢ

http://www.hackerschool.org/HS_Boards/zboard.php?id=QNA_programming&no=6588 []


ü  ϴ 𸣰ھ.
𸣰ڰ  ̰Ÿ Ǯ 𸣰ھ.
б ε Բ ֽ Ű Ф
ڵ ߰ ٰ ҽϴ. Ʋ ⵵ ؿ Ф
# ִ°Ŵ ֽ ƮԴϴ.



# pascal.py: takes an integer n as command-line argument and writes
# Pascal's triangle P_n.

import stdarray
import stdio
import sys

# Get n from command line, as an int.
n = int(sys.argv[1])

# Construct a 2D ragged list a of integers. The list must have n + 1 rows,
# with the ith (0 <= i <= n) row a[i] having i + 1 elements, each initialized
# to 1. For example, if n = 3, a should be initialized to
# [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]].
a = int[stdarray.create2D(n+1,n, 0.0 )]
for i in range[a]:
    a += [a[i]]

# Fill the ragged list a using the formula for Pascal's triangle
#     a[i][j] = a[i - 1][j - 1] + a[i - 1][j]
# where 0 <= i <= n and 1 <= j < i.
for i in range(0, n):
    for j in range(1, i):
        a[i][j] = a[i - 1][j - 1] + a[i-1][j]

# Write out the ragged list a, with elements separated by spaces, and each
# row ending in a newline.
for i in range(...):
    for j in range(..., ...):
        if j < i:
            
        else:  # end of a row
            ...

  Hit : 3855     Date : 2017/10/14 12:32



    
gaelim ... ̽ 𸣴µ.
켱 ĽĮ ﰢ̸ õ ڳ׿
ϴ
# Construct a 2D ragged list a of integers. The list must have n + 1 rows,
# with the ith (0 <= i <= n) row a[i] having i + 1 elements, each initialized
# to 1. For example, if n = 3, a should be initialized to
# [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]].

κп, n +1 ŭ, n+1ŭ 2D array ϴµ 1 ʱȭ϶׿.
̽㿡 ϴ° ߸󼭿,
ϴ ̰ 2 for ҰŰ׿

for i=0 to i<=n
for j=0 to j<=i
a.push(1)
̷ ϸ
[[1], [1,1], [1,1,1], [1,1,1,1] ] ̷ ðŰ

ĽĮ ﰢ δ
1
1 1
1 2 1
1 3 3 1
̷ ݾƿ
ٵ 迭 (̽㿡 Ʈ?) ٸ
1
1 1
1 2 1
1 3 3 1
̷ ǿ  ǵϴ°ó

1
1 1
1 1* 1
1 1 1 1
⼭ ϴµ

1* κ ش i(row,) 2, j(column,) 1̿
a[2][1] = a[1][0]+a[1][1] Ǵ°ſ

ٵ ۼں ۼϽŰ ϱ

# Fill the ragged list a using the formula for Pascal's triangle
# a[i][j] = a[i - 1][j - 1] + a[i - 1][j]
# where 0 <= i <= n and 1 <= j < i.
for i in range(0, n):
for j in range(1, i):
a[i][j] = a[i - 1][j - 1] + a[i-1][j]

̷ ִµ ּ 0<=i<=n, 1<=j<i Ʈ ִµ
ۼϽŰźϱ for ȣϳ׿ (0, n) (1, i) εȣ Ѱ ߸ȰŰ? ̺κ ݵ Ͻñ

ּκп
# Write out the ragged list a, with elements separated by spaces, and each
# row ending in a newline.
Ǿִµ

϶°Ű

ϴ ϽǶ¿ ̷ ϸǿ CóغԿ

for (int i=0; i<=n; i++){
for (int j=i; j<n; j++){
printf(" ");
}
for (int j=0; j<=i; j++){
printf("%d ", a[i]); // "%d " <-- ̽ Ѱ ϼ ^^;;
}
printf("\n");
}

̷ ϸ ڰ ڳ׿ ^^;;
2017/10/15  
3186     [re] c ˰ Դϴ.     dafher
05/13 1559
3185   c ҽ ̤̤̤[2]     sjjh96
05/23 4200
3184   ̽ Ŭ [1]     wnsdud5534
04/12 3401
3183   dll Ű ŷ(win32api)[1]     healer
03/11 3265
3182   C++ Լ ε Դϴ. [1]     sweetick
03/04 5428
3181   Ϳ ޸𸮸 ִ° ұ??[3]     ljs0652
01/24 2201
3180   File Descriptor Դϴ.     tjdalstjr938
01/22 1998
3179   C [2]     rhdbrkd2
01/02 2624
3178   C θ Ϸ ϴµ...[3]     rhdbrkd2
12/15 3484
3177   c ü 迭 ͷ Լ ϴµ...[3]     my10045139
12/13 6019
3176   ٸ ڵ      yyy3399
12/09 3049
3175   ڹ å, å, å (3 å õٶϴ.)[1]     viewstar
11/26 3403
3174   ڹ α׷ α׷ 帳ϴ.[2]     daze1234
10/27 4447
  ̽: ĽĮ ﰢ[1]     sunnykim97
10/14 3854
3172   visual studio 2017 c++ µ ذ 𸣰ھФ     93jmj
10/13 3154
3171   α׷ 2[1]     ysl1121
09/19 3851
3170   C(C) Ǯ Ǯ Ф[5]     ijs2you
08/28 3550
3169   c ߴµ ο ҽ ߰ؾϳ?[5]     Newbiee
05/10 2956
3168   ̽ ڵ尡 Ф[1]     zero1
04/29 3265
3167   ־ ڵۼȰŶ ´ּ..     lia9173
04/05 2530
[1] 2 [3][4][5][6][7][8][9][10]..[161]

Copyright 1999-2024 Zeroboard / skin by Hackerschool.org / Secure Patch by Hackerschool.org