-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/KNU-HAEDAL/2024-SS-small-gr…
- Loading branch information
Showing
6 changed files
with
177 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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,39 @@ | ||
""" | ||
원하는 카드 뭉치에서 카드를 순서대로 한 장씩 사용 | ||
한 번 사용한 카드는 다시 사용 X | ||
카드 사용하지 않고 다음 카드로 못넘어감 | ||
기존에 주어진 카드 뭉치 단어 순서 못바꿈 | ||
""" | ||
|
||
from collections import deque | ||
|
||
def solution(cards1, cards2, goal): | ||
cards1 = deque(cards1) | ||
cards2 = deque(cards2) | ||
goal = deque(goal) | ||
|
||
for i in range(len(goal)): | ||
if cards1 and (cards1[0] == goal[0]): #cards1의 원소와 먼저 비교 | ||
cards1.popleft() | ||
goal.popleft() | ||
elif cards2 and (cards2[0] == goal[0]): #그 다음 cards2의 원소와 비교 | ||
cards2.popleft() | ||
goal.popleft() | ||
else: | ||
break | ||
return "Yes" if not goal else "No" #이 부분 체크 | ||
# 첫 실행때 밑에 부분 복붙해오느라 쉼표 그대로 들어왔더니 리스트가 아니라 튜플이 되어서 오류가 떠버림 | ||
# cards1, cards2, goal과 같이 리스트 정의할 때 쉼표 들어가서 튜플이 되어버리는 것 주의.. 근데 왜인지 알아봐야 함ㅎ | ||
cards1 = ["i", "drink", "water"] | ||
cards2 = ["want", "to"] | ||
goal = ["i", "want", "to", "drink", "water"] | ||
|
||
print(solution(cards1, cards2, goal)) | ||
|
||
cards11 = ["i", "water", "drink"] | ||
cards22 = ["want", "to"] | ||
goal = ["i", "want", "to", "drink", "water"] | ||
print(solution(cards11, cards22, goal)) | ||
#입출력 예 | ||
# cards1 = ["i", "drink", "water"], cards2 = ["want", "to"], goal = ["i", "want", "to", "drink", "water"], result = "Yes" | ||
# cards1 = ["i", "water", "drink"], cards2 = ["want", "to"], goal = ["i", "want", "to", "drink", "water"], result = "No" |
This file contains 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,47 @@ | ||
""" | ||
n개의 양의 정수로 이루어진 리스트 arr와 정수 target이 주어졌을 때 | ||
이 중에서 합이 target인 두 수가 arr에 있는지 찾고 | ||
있으면 True, 없으면 False를 반환하는 solution() 함수를 작성 | ||
n은 2 이상 10000 이하의 자연수 | ||
arr의 각 원소는 1 이상 10000 이하의 자연수 | ||
arr의 원소 중 중복되는 원소는 없음 | ||
target은 1 이상 20000 이하의 자연수 | ||
""" | ||
|
||
def count_sort(arr, k): #target 값이 K로 들어감 | ||
hash_table = [0] * (k + 1) | ||
#어쨋든 target 값보다 큰 값이 더해져버리면 안되니까 target 값 보다 작으면 그냥 0의 값으로 둬도 됨 | ||
for i in arr: | ||
if i <= k: | ||
hash_table[i] = 1 | ||
return hash_table | ||
|
||
|
||
def solution(arr, target): | ||
hash_table = count_sort(arr, target) | ||
# i + minus = target | ||
for i in arr: | ||
minus = target - i | ||
print(minus) | ||
# 이제 minus에 해당하는 값이 해시테이블 내에 존재하는지 (1인지 판단) | ||
if ((hash_table[minus] == 1) and (minus != i)): | ||
return True | ||
return False | ||
|
||
arr1 = [1, 2, 3, 4, 8] | ||
target1 = 6 | ||
arr2 = [2, 3, 5, 9] | ||
target2 = 10 | ||
|
||
print(solution(arr1, target1)) | ||
print(solution(arr2, target2)) | ||
|
||
# 뭐임 왜 두번째 True 뜨냐.. | ||
""" | ||
2, 3, 5, 9 = 1 | ||
10 - 2 = 8 | ||
10 - 3 = 7 | ||
10 - 5 = 5 <- 얘 같으니까 안되잖아 | ||
10 - 9 = 1 | ||
""" |
This file contains 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,41 @@ | ||
""" | ||
한 명 제외하고 모든 선수가 완주함 | ||
마라톤에 참여한 선수들 이름 담긴 배열 participant | ||
완주한 선수들의 이름이 담긴 배열 completion | ||
완주하지 못한 선수의 이름을 반환하는 solution() 함수 | ||
마라톤 경기에 참여한 선수 수는 1명 이상 100000명 이하 | ||
completion 길이는 participant 길이보다 1 작음 | ||
참가자 이름은 1개 이상 20개 이하의 알파벳 소문자 | ||
참가자 중 동명이인 ㄱㄴ | ||
""" | ||
|
||
def solution(participant, completion): | ||
completion_check = {} | ||
|
||
for part in participant: | ||
if part in completion_check: | ||
completion_check[part] += 1 | ||
else: | ||
completion_check[part] = 1 | ||
|
||
for comp in completion: | ||
completion_check[comp] -= 1 | ||
|
||
for athelte in completion_check.keys(): | ||
if completion_check[athelte] > 0: | ||
return athelte | ||
|
||
participant1 = ["leo", "kiki", "eden"] | ||
completion1 = ["eden", "kiki"] | ||
#return = ["leo"] | ||
participant2 = ["marina", "josipa", "nikola", "vinko", "filipa"] | ||
completion2 = ["josipa", "filipa", "marina", "nikola"] | ||
#return = ["vinko"] | ||
participant3 = ["mislav", "stanko", "mislav", "ana"] #동명이인 존재 case | ||
completion3 = ["stanko", "ana", "mislav"] | ||
#return = ["mislav"] | ||
|
||
print(solution(participant1, completion1)) | ||
print(solution(participant2, completion2)) | ||
print(solution(participant3, completion3)) |
This file contains 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,38 @@ | ||
def solution(want, number, discount): # 쇼핑리스트 출력 | ||
|
||
shop_list = {} | ||
for i in range(len(want)): | ||
shop_list[want[i]] = number[i] | ||
|
||
count = 0 | ||
for i in range(len(discount) - 9): | ||
discount_list = {} #할인 받을 수 있는 상품 리스트 | ||
|
||
for j in range(i, i + 10): # range(j + 10) -> range(i, i + 10) | ||
item = discount[j] | ||
if item in discount_list: | ||
discount_list[item] += 1 #할인 받을 수 있는 상품 갯수를 차곡차곡 쌓아나간다는 느낌으로.. | ||
else: | ||
discount_list[item] = 1 | ||
|
||
if (shop_list == discount_list): | ||
count += 1 | ||
return count | ||
|
||
want1 = ["banana", "apple", "rice", "pork", "pot"] #원하는 제품 문자열 | ||
number1 = [3, 2, 2, 2, 1] #원하는 제품의 수량 | ||
# 마트에서 할인하는 제품 | ||
discount1 = ["chicken", "apple", "apple", "banana", "rice", "apple", "pork", "banana", "pork", "rice", "pot", "banana", "apple", "banana"] | ||
|
||
want2 = ["apple"] | ||
number2 = [10] | ||
discount2 = ["banana", "banana", "banana", "banana", "banana", "banana", "banana", "banana", "banana", "banana"] | ||
|
||
print(solution(want1, number1, discount1)) | ||
print(solution(want2, number2, discount2)) | ||
|
||
""" | ||
바나나 3 사과 2 쌀 2 돼지고기 2 냄비 1 | ||
치킨 사과 사과 바나나 쌀 사과 돼지고기 바나나 돼지고기 쌀 냄비 바나나 사과 바나나 | ||
사과 사과 바나나 쌀 돼지고기 바나나 돼지고기 쌀 냄비 바나나 | ||
""" |
This file contains 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
This file contains 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 |
---|---|---|
@@ -1 +1 @@ | ||
175 | ||
177 |