α׷

 3206, 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 : 3917     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  
46   sniffing ֽϴ..     ssk1547
12/11 2359
45   c++ ٸŬ ͼ ̿[2]     Թ
02/02 15935
44   ̽ մϴ.[1]     cgw0525
02/27 2271
43   ҽ ҽڵ[1]     ewqqw
03/08 3380
42   C python subprocess ֳ?[3]     vngkv123
03/17 3313
41   Ǵµ ȵdz׿ Ф[2]     sgolds
03/26 3875
40   ־ ڵۼȰŶ ´ּ..     lia9173
04/05 2600
39   ̽ ڵ尡 Ф[1]     zero1
04/29 3348
38   c ߴµ ο ҽ ߰ؾϳ?[5]     Newbiee
05/10 2996
37   C(C) Ǯ Ǯ Ф[5]     ijs2you
08/28 3657
36   α׷ 2[1]     ysl1121
09/19 3916
35   visual studio 2017 c++ µ ذ 𸣰ھФ     93jmj
10/13 3211
  ̽: ĽĮ ﰢ[1]     sunnykim97
10/14 3916
33   ڹ α׷ α׷ 帳ϴ.[2]     daze1234
10/27 4528
32   ڹ å, å, å (3 å õٶϴ.)[1]     viewstar
11/26 3529
31   ٸ ڵ      yyy3399
12/09 3181
30   c ü 迭 ͷ Լ ϴµ...[3]     my10045139
12/13 6100
29   C θ Ϸ ϴµ...[3]     rhdbrkd2
12/15 3582
28   C [2]     rhdbrkd2
01/02 2675
27   File Descriptor Դϴ.     tjdalstjr938
01/22 2035
[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