α׷

 3204, 159/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 : 3929     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  
44   sniffing ֽϴ..     ssk1547
12/11 2365
43   c++ ٸŬ ͼ ̿[2]     Թ
02/02 15964
42   ̽ մϴ.[1]     cgw0525
02/27 2276
41   ҽ ҽڵ[1]     ewqqw
03/08 3389
40   C python subprocess ֳ?[3]     vngkv123
03/17 3333
39   Ǵµ ȵdz׿ Ф[2]     sgolds
03/26 3902
38   ־ ڵۼȰŶ ´ּ..     lia9173
04/05 2612
37   ̽ ڵ尡 Ф[1]     zero1
04/29 3360
36   c ߴµ ο ҽ ߰ؾϳ?[5]     Newbiee
05/10 3002
35   C(C) Ǯ Ǯ Ф[5]     ijs2you
08/28 3677
34   α׷ 2[1]     ysl1121
09/19 3927
33   visual studio 2017 c++ µ ذ 𸣰ھФ     93jmj
10/13 3217
  ̽: ĽĮ ﰢ[1]     sunnykim97
10/14 3928
31   ڹ α׷ α׷ 帳ϴ.[2]     daze1234
10/27 4541
30   ڹ å, å, å (3 å õٶϴ.)[1]     viewstar
11/26 3541
29   ٸ ڵ      yyy3399
12/09 3195
28   c ü 迭 ͷ Լ ϴµ...[3]     my10045139
12/13 6117
27   C θ Ϸ ϴµ...[3]     rhdbrkd2
12/15 3595
26   C [2]     rhdbrkd2
01/02 2683
25   File Descriptor Դϴ.     tjdalstjr938
01/22 2043
[1]..[151][152][153][154][155][156][157][158] 159 [160]..[161]

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