From b7ce4231c2e3347b2195c7746d60c18e942f5737 Mon Sep 17 00:00:00 2001 From: Seong Joon Hee Date: Sun, 9 Apr 2023 00:15:18 +0900 Subject: [PATCH 1/7] =?UTF-8?q?#2=20:=2015649=5FN=EA=B3=BC=20M(1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../15649_N\352\263\274 M(1).py" | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 "\354\235\264\355\213\260\354\244\200\355\235\254/15649_N\352\263\274 M(1).py" diff --git "a/\354\235\264\355\213\260\354\244\200\355\235\254/15649_N\352\263\274 M(1).py" "b/\354\235\264\355\213\260\354\244\200\355\235\254/15649_N\352\263\274 M(1).py" new file mode 100644 index 0000000..657397f --- /dev/null +++ "b/\354\235\264\355\213\260\354\244\200\355\235\254/15649_N\352\263\274 M(1).py" @@ -0,0 +1,25 @@ +#2023-04-06-Week1 +#15649_N과 M(1) + +#itertools의 permutations 함수를 사용해서 풀어보자 +#permutations(iterable, r) : iterable에서 원소 개수가 r개인 순열을 뽑는 것 + +import itertools +import sys +#from itertools import permutations -> 함수 사용시 도트연산자 앞부분 생략 가능 + +n, m = map(int, input().split()) + +nums = [i for i in range(1, n+1)] + +nums = [] +for i in range(1, n+1) : + nums.append(i) + +arr = itertools.permutations(nums, m) + + +for i in arr : #리스트 원소 개수 -> set이 하나 + for j in i : + print(j, end=' ') + print() \ No newline at end of file From d7053ee4601d6209ed3c87fd1e7f6dbf6bcfab5a Mon Sep 17 00:00:00 2001 From: Seong Joon Hee Date: Sun, 9 Apr 2023 01:11:00 +0900 Subject: [PATCH 2/7] =?UTF-8?q?#2=20:=201978=5F=EC=86=8C=EC=88=98=20?= =?UTF-8?q?=EC=B0=BE=EA=B8=B0.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\210\230 \354\260\276\352\270\260.py" | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 "\354\235\264\355\213\260\354\244\200\355\235\254/1978_\354\206\214\354\210\230 \354\260\276\352\270\260.py" diff --git "a/\354\235\264\355\213\260\354\244\200\355\235\254/1978_\354\206\214\354\210\230 \354\260\276\352\270\260.py" "b/\354\235\264\355\213\260\354\244\200\355\235\254/1978_\354\206\214\354\210\230 \354\260\276\352\270\260.py" new file mode 100644 index 0000000..95a8e84 --- /dev/null +++ "b/\354\235\264\355\213\260\354\244\200\355\235\254/1978_\354\206\214\354\210\230 \354\260\276\352\270\260.py" @@ -0,0 +1,40 @@ +#2023-04-08-Week1-과제 +#1978_소수 찾기 + +''' +입력 1 - 수의 개수 N < 100 +입력 2 - 1000 이하의 자연수 N개 +결과 - 입력2의 자연수 중 소수의 개수 출력 +''' + +#입력 받는 값 여러 개 -> map 함수 + + +n = int(input("입력 : \n")) + +num = list(map (int, input().split())) # 자료형, 함수 (.split() 공백으로 구분) + +result = 0 # 입력한 자연수 중 소수의 개수 + +for i in num : # 입력 받은 수들을 소수 확인 대상 i로 설정 + cnt = 0 # 소수 확인 대상의 약수 개수 + if i == 1 : # 1은 소수 아님 + continue + + for j in range (2, i+1) : # 2~i까지 + if (i%j == 0) : # 소수 확인 대상이 2부터 자기 자신으로 나눴을 때 0 이 되면 + cnt += 1 # 약수 개수 증가 + + if cnt == 1 : # 약수의 개수 1개 + result += 1 # 소수 개수 추가 + +print ("출력 : ", result) # 출력 : 입력 자연수 중 소수의 개수 + + + + + + + + + From e734ce3d193ba84241bfdaceb1d0a23eeddb4469 Mon Sep 17 00:00:00 2001 From: Seong Joon Hee Date: Sun, 9 Apr 2023 01:14:00 +0900 Subject: [PATCH 3/7] =?UTF-8?q?#2=20:=201978=5F=EC=86=8C=EC=88=98=20?= =?UTF-8?q?=EC=B0=BE=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...978_\354\206\214\354\210\230 \354\260\276\352\270\260.py" | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git "a/\354\235\264\355\213\260\354\244\200\355\235\254/1978_\354\206\214\354\210\230 \354\260\276\352\270\260.py" "b/\354\235\264\355\213\260\354\244\200\355\235\254/1978_\354\206\214\354\210\230 \354\260\276\352\270\260.py" index 95a8e84..621245a 100644 --- "a/\354\235\264\355\213\260\354\244\200\355\235\254/1978_\354\206\214\354\210\230 \354\260\276\352\270\260.py" +++ "b/\354\235\264\355\213\260\354\244\200\355\235\254/1978_\354\206\214\354\210\230 \354\260\276\352\270\260.py" @@ -7,12 +7,9 @@ 결과 - 입력2의 자연수 중 소수의 개수 출력 ''' -#입력 받는 값 여러 개 -> map 함수 - - n = int(input("입력 : \n")) -num = list(map (int, input().split())) # 자료형, 함수 (.split() 공백으로 구분) +num = list(map (int, input().split())) # 입력 받는 값 여러 개 -> map 함수 : 자료형, 함수 (.split() 공백으로 구분) result = 0 # 입력한 자연수 중 소수의 개수 From 8b87499ede50a59a25b83b3c0f2980f3acfd0de7 Mon Sep 17 00:00:00 2001 From: Seong Joon Hee Date: Wed, 12 Apr 2023 12:53:12 +0900 Subject: [PATCH 4/7] =?UTF-8?q?#2=20:=2015650=5FN=EA=B3=BC=20M(2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../15650_N\352\263\274 M(2).py" | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 "\354\235\264\355\213\260\354\244\200\355\235\254/15650_N\352\263\274 M(2).py" diff --git "a/\354\235\264\355\213\260\354\244\200\355\235\254/15650_N\352\263\274 M(2).py" "b/\354\235\264\355\213\260\354\244\200\355\235\254/15650_N\352\263\274 M(2).py" new file mode 100644 index 0000000..1c1ad5f --- /dev/null +++ "b/\354\235\264\355\213\260\354\244\200\355\235\254/15650_N\352\263\274 M(2).py" @@ -0,0 +1,29 @@ +#2023-04-08-Week1-과제 +#15650_N과 M(2) + +''' +자연수 N과 M이 주어졌을 때, 아래 조건을 만족하는 길이가 M인 수열을 모두 구하는 프로그램을 작성하시오. + +1부터 N까지 자연수 중에서 중복 없이 M개를 고른 수열 +고른 수열은 오름차순이어야 한다. + +입력 : 첫째 줄에 자연수 N과 M이 주어진다. (1 ≤ M ≤ N ≤ 8) +출력 : 한 줄에 하나씩 문제의 조건을 만족하는 수열을 출력한다. 중복되는 수열을 여러 번 출력하면 안되며, 각 수열은 공백으로 구분해서 출력해야 한다. + +수열은 사전 순으로 증가하는 순서로 출력해야 한다. + +''' +import itertools + +n,m = map(int,input().split()) + +num = itertools.combinations([i for i in range(1,n+1)],m) + +for i in num : + j = itertools.permutations(i) #permutation 가능한 모든 순열 + for k in j : + if k == sorted(k) : #오름차순으로 정렬된 경우면 출력 + print(" ".join(map(str, k))) + #map k의 요소들을 문자열로 반환 + #join 리스트 요소를 문자열로 연결 + #" "로 요소 사이에 구분자 \ No newline at end of file From 1fe0fcd75502db1ed685fc7c6bc0838b6cdc5a97 Mon Sep 17 00:00:00 2001 From: Seong Joon Hee Date: Thu, 13 Apr 2023 14:32:35 +0900 Subject: [PATCH 5/7] =?UTF-8?q?#10=20:=20=ED=94=84=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EB=9E=98=EB=A8=B8=EC=8A=A4=20Level=202=20=EC=A0=84=ED=99=94?= =?UTF-8?q?=EB=B2=88=ED=98=B8=20=EB=AA=A9=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\355\230\270 \353\252\251\353\241\235.py" | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 "\354\235\264\355\213\260\354\244\200\355\235\254/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244 Level 2 \354\240\204\355\231\224\353\262\210\355\230\270 \353\252\251\353\241\235.py" diff --git "a/\354\235\264\355\213\260\354\244\200\355\235\254/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244 Level 2 \354\240\204\355\231\224\353\262\210\355\230\270 \353\252\251\353\241\235.py" "b/\354\235\264\355\213\260\354\244\200\355\235\254/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244 Level 2 \354\240\204\355\231\224\353\262\210\355\230\270 \353\252\251\353\241\235.py" new file mode 100644 index 0000000..e2093b7 --- /dev/null +++ "b/\354\235\264\355\213\260\354\244\200\355\235\254/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244 Level 2 \354\240\204\355\231\224\353\262\210\355\230\270 \353\252\251\353\241\235.py" @@ -0,0 +1,59 @@ +#2023-04-13-Week2 +#프로그래머스 Level 2 전화번호 목록.py + +#hash <- dict : key, value + +''' +문제 설명 +전화번호부에 적힌 전화번호 중, 한 번호가 다른 번호의 접두어인 경우가 있는지 확인하려 합니다. +전화번호가 다음과 같을 경우, 구조대 전화번호는 영석이의 전화번호의 접두사입니다. + +구조대 : 119 +박준영 : 97 674 223 +지영석 : 11 9552 4421 +전화번호부에 적힌 전화번호를 담은 배열 phone_book 이 solution 함수의 매개변수로 주어질 때, 어떤 번호가 다른 번호의 접두어인 경우가 있으면 false를 그렇지 않으면 true를 return 하도록 solution 함수를 작성해주세요. + +제한 사항 +phone_book의 길이는 1 이상 1,000,000 이하입니다. +각 전화번호의 길이는 1 이상 20 이하입니다. +같은 전화번호가 중복해서 들어있지 않습니다. +''' + +#key value 동일하게 초기화 + +''' +문자열에 원하는 문자가 있는지 확인하는 방법 in 문자열 + +text = "hello joonhee" + +if "joon" in text : + print("T") +else : + print("F") +''' + + +def solution(phone_book): + answer = True + hash = {} + + for i in phone_book : + hash[i] = 0 + + print(hash) + print("--------") + + for i in phone_book : + print(i) + print("--------") + + temp ='' + for j in i : + temp+=j + if temp in hash and temp != i : + answer = False + return answer + +#print(solution(["12","3456","789"])) +solution(["12","3456","789"]) + From 79b802e39c4309c6ef500a4e7ff287001eaef276 Mon Sep 17 00:00:00 2001 From: Seong Joon Hee Date: Thu, 13 Apr 2023 19:14:43 +0900 Subject: [PATCH 6/7] =?UTF-8?q?#2=20:=201978=5F=EC=86=8C=EC=88=98=20?= =?UTF-8?q?=EC=B0=BE=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...8_\354\206\214\354\210\230 \354\260\276\352\270\260.py" | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git "a/\354\235\264\355\213\260\354\244\200\355\235\254/1978_\354\206\214\354\210\230 \354\260\276\352\270\260.py" "b/\354\235\264\355\213\260\354\244\200\355\235\254/1978_\354\206\214\354\210\230 \354\260\276\352\270\260.py" index 621245a..284f05f 100644 --- "a/\354\235\264\355\213\260\354\244\200\355\235\254/1978_\354\206\214\354\210\230 \354\260\276\352\270\260.py" +++ "b/\354\235\264\355\213\260\354\244\200\355\235\254/1978_\354\206\214\354\210\230 \354\260\276\352\270\260.py" @@ -7,7 +7,8 @@ 결과 - 입력2의 자연수 중 소수의 개수 출력 ''' -n = int(input("입력 : \n")) +n = int(input()) +#feedback ) n = int(input("입력 : \n")) -> input 내부에 추가적인 멘트 작성 x num = list(map (int, input().split())) # 입력 받는 값 여러 개 -> map 함수 : 자료형, 함수 (.split() 공백으로 구분) @@ -25,7 +26,9 @@ if cnt == 1 : # 약수의 개수 1개 result += 1 # 소수 개수 추가 -print ("출력 : ", result) # 출력 : 입력 자연수 중 소수의 개수 +print (result) # 출력 : 입력 자연수 중 소수의 개수 + +#feedback ) print ("출력 : ", result) -> 출력시 추가적인 멘트 x From f857ba8a225553c2ceb2fecbcb3c6103ac3ebf7e Mon Sep 17 00:00:00 2001 From: Seong Joon Hee Date: Thu, 13 Apr 2023 19:15:28 +0900 Subject: [PATCH 7/7] =?UTF-8?q?#2=20:=2015650=5FN=EA=B3=BC=20M(2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../15650_N\352\263\274 M(2).py" | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git "a/\354\235\264\355\213\260\354\244\200\355\235\254/15650_N\352\263\274 M(2).py" "b/\354\235\264\355\213\260\354\244\200\355\235\254/15650_N\352\263\274 M(2).py" index 1c1ad5f..38afafe 100644 --- "a/\354\235\264\355\213\260\354\244\200\355\235\254/15650_N\352\263\274 M(2).py" +++ "b/\354\235\264\355\213\260\354\244\200\355\235\254/15650_N\352\263\274 M(2).py" @@ -13,10 +13,12 @@ 수열은 사전 순으로 증가하는 순서로 출력해야 한다. ''' -import itertools -n,m = map(int,input().split()) +''' +#feedback ) combinations 만 사용해도 풀이 가능 +from itertools +n,m = map(int,input().split()) num = itertools.combinations([i for i in range(1,n+1)],m) for i in num : @@ -26,4 +28,18 @@ print(" ".join(map(str, k))) #map k의 요소들을 문자열로 반환 #join 리스트 요소를 문자열로 연결 - #" "로 요소 사이에 구분자 \ No newline at end of file + #" "로 요소 사이에 구분자 +''' +from itertools import combinations + +n,m = map(int,input().split()) + +arr = [] +for i in range(1,n+1): + arr.append(i) + +for i in combinations(arr,m): + for j in i: + print(j, end=' ') + print() +