α׷

 3206, 1/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 : 3895     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  
3206   SNSŷ dz? ּ ФФ [1]     ä
02/28 324
3205   ġƮ DZ[1]     rjsdudals123
02/15 182
3204   ãּ [1]     marunim
05/30 913
3203 бԴϴ  124     minsub87
08/17 1
3202   c segmentation fault:11 帳ϴ![2]     leebk1124
05/21 2002
3201   C++Լ ̿!![3]     1999dylee
05/11 1836
3200   ̽ 帳ϴ.[1]     kksh1107
04/24 1577
3199   - -     nninni79
04/20 2280
3198   ް ڵ[1]     ghjk645
03/24 1597
3197 бԴϴ  c Ҽ      adwefq
04/29 0
3196   C ҽԴϴ![5]     an0088
01/05 5106
3195   C++ /// Ф[1]     guichanta
08/23 2389
3194 бԴϴ  c ּФ     su6339
04/06 0
3193   ŷ ϴµ[3]     zoodem04
03/26 4176
3192   c ; ![7]     dwc07238
02/11 4056
3191   ̴ ⿡ ؼ!![1]     hackxx123
12/10 3508
3190   ŷ ip ϵ忡 ɴ°ſ  ?[2]     aowlrgmlals
11/27 4261
3189   C ϴµ double Ǽ ڲ 0.0 Ϳ[2]     fatou10336
11/20 3713
3188   dumpcode.h ּ .[1]     cm6418
11/06 3693
3187   c ˰ Դϴ.[3]     alstn8150
10/12 3718
1 [2][3][4][5][6][7][8][9][10]..[161]

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