파이썬/파이썬 문제
15649 - n과m(1)
백수진
2021. 3. 18. 01:21
array= [0]*10
check=[0]*10
n = int(input())
m = int(input())
def fun(n,m,cnt):
if cnt==m:
for i in range(0,cnt):
print(array[i],end = '')
print()
return
else:
for i in range(1,n+1):
if check[i]!=1:
check[i] = 1
array[cnt] = i
fun(n,m,cnt+1)
check[i]=0
fun(n,m,0)
< 알게 된 점>
배열 출력시, %d를 안 쓰고 array[i]를 사용해서 그냥 출력이 가능
input할 때, map과 split()을 활용하면 쉬움
=> n,m = map(int,input().split())으로 바꿔서 사용해봄
cnt를 통해서 array[cnt]로 array배열에 값을 저장해주고 만약에 cnt가 m과 같아진다면 m-1까지 array[]에 들어있는 것이기에 cnt전까지 0부터 출력하면 오름차순으로 for문을 작성해서 오름차순으로 출력됨.