Repository navigation
#2 : Week1_준희이티 #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b7ce423
#2 : 15649_N과 M(1)
devCharlotte d7053ee
#2 : 1978_소수 찾기.py
devCharlotte e734ce3
#2 : 1978_소수 찾기
devCharlotte 8b87499
#2 : 15650_N과 M(2)
devCharlotte 1fe0fcd
#10 : 프로그래머스 Level 2 전화번호 목록
devCharlotte 79b802e
#2 : 1978_소수 찾기
devCharlotte f857ba8
#2 : 15650_N과 M(2)
devCharlotte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| #2023-04-08-Week1-과제 | ||
| #15650_N과 M(2) | ||
|
|
||
| ''' | ||
| 자연수 N과 M이 주어졌을 때, 아래 조건을 만족하는 길이가 M인 수열을 모두 구하는 프로그램을 작성하시오. | ||
|
|
||
| 1부터 N까지 자연수 중에서 중복 없이 M개를 고른 수열 | ||
| 고른 수열은 오름차순이어야 한다. | ||
|
|
||
| 입력 : 첫째 줄에 자연수 N과 M이 주어진다. (1 ≤ M ≤ N ≤ 8) | ||
| 출력 : 한 줄에 하나씩 문제의 조건을 만족하는 수열을 출력한다. 중복되는 수열을 여러 번 출력하면 안되며, 각 수열은 공백으로 구분해서 출력해야 한다. | ||
|
|
||
| 수열은 사전 순으로 증가하는 순서로 출력해야 한다. | ||
|
|
||
| ''' | ||
|
|
||
|
|
||
| ''' | ||
| #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 : | ||
| j = itertools.permutations(i) #permutation 가능한 모든 순열 | ||
| for k in j : | ||
| if k == sorted(k) : #오름차순으로 정렬된 경우면 출력 | ||
| print(" ".join(map(str, k))) | ||
| #map k의 요소들을 문자열로 반환 | ||
| #join 리스트 요소를 문자열로 연결 | ||
| #" "로 요소 사이에 구분자 | ||
| ''' | ||
| 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() | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| #2023-04-08-Week1-과제 | ||
| #1978_소수 찾기 | ||
|
|
||
| ''' | ||
| 입력 1 - 수의 개수 N < 100 | ||
| 입력 2 - 1000 이하의 자연수 N개 | ||
| 결과 - 입력2의 자연수 중 소수의 개수 출력 | ||
| ''' | ||
|
|
||
| n = int(input()) | ||
| #feedback ) n = int(input("입력 : \n")) -> input 내부에 추가적인 멘트 작성 x | ||
|
|
||
| num = list(map (int, input().split())) # 입력 받는 값 여러 개 -> map 함수 : 자료형, 함수 (.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) # 출력 : 입력 자연수 중 소수의 개수 | ||
|
|
||
| #feedback ) print ("출력 : ", result) -> 출력시 추가적인 멘트 x | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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"]) | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 문제에서는 permutation 함수를 사용할 필요 없이 combinations 함수만 사용해도 답을 구할 수 있습니다! combinations 함수의 특징을 다시 한 번 확인하신 후 문제를 풀어보시면 좋을 것 같아요!