Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
seongwon02 committed Aug 13, 2024
2 parents 766d789 + 2d60277 commit d1577ea
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 12 deletions.
39 changes: 39 additions & 0 deletions HJBAE/11to20/17.py
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"
47 changes: 47 additions & 0 deletions HJBAE/11to20/18.py
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
"""
41 changes: 41 additions & 0 deletions HJBAE/11to20/20.py
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))
38 changes: 38 additions & 0 deletions HJBAE/21to30/21.py
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
치킨 사과 사과 바나나 쌀 사과 돼지고기 바나나 돼지고기 쌀 냄비 바나나 사과 바나나
사과 사과 바나나 쌀 돼지고기 바나나 돼지고기 쌀 냄비 바나나
"""
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
<td> Python : 3&nbsp&nbsp&nbsp&nbspJava : 0&nbsp&nbsp&nbsp&nbspC : 0&nbsp&nbsp&nbsp&nbsp&nbspC++ : 0&nbsp&nbsp&nbsp&nbsp&nbspC# : 0</td>
</tr> <tr>
<td> 김성원 </td>
<td> 70 </td>
<td> 70 </td>
<td> 30 </td>
<td> -30000 </td>
<td> Python : 70&nbsp&nbsp&nbsp&nbspJava : 0&nbsp&nbsp&nbsp&nbspC : 0&nbsp&nbsp&nbsp&nbsp&nbspC++ : 0&nbsp&nbsp&nbsp&nbsp&nbspC# : 0</td>
<td> 71 </td>
<td> 71 </td>
<td> 29 </td>
<td> -29000 </td>
<td> Python : 71&nbsp&nbsp&nbsp&nbspJava : 0&nbsp&nbsp&nbsp&nbspC : 0&nbsp&nbsp&nbsp&nbsp&nbspC++ : 0&nbsp&nbsp&nbsp&nbsp&nbspC# : 0</td>
</tr> <tr>
<td> 김희수 </td>
<td> 21 </td>
Expand All @@ -36,11 +36,11 @@
<td> Python : 21&nbsp&nbsp&nbsp&nbspJava : 0&nbsp&nbsp&nbsp&nbspC : 0&nbsp&nbsp&nbsp&nbsp&nbspC++ : 0&nbsp&nbsp&nbsp&nbsp&nbspC# : 0</td>
</tr> <tr>
<td> 배현진 </td>
<td> 15 </td>
<td> 18 </td>
<td> 85 </td>
<td> -85000 </td>
<td> Python : 18&nbsp&nbsp&nbsp&nbspJava : 0&nbsp&nbsp&nbsp&nbspC : 0&nbsp&nbsp&nbsp&nbsp&nbspC++ : 0&nbsp&nbsp&nbsp&nbsp&nbspC# : 0</td>
<td> 19 </td>
<td> 22 </td>
<td> 81 </td>
<td> -81000 </td>
<td> Python : 22&nbsp&nbsp&nbsp&nbspJava : 0&nbsp&nbsp&nbsp&nbspC : 0&nbsp&nbsp&nbsp&nbsp&nbspC++ : 0&nbsp&nbsp&nbsp&nbsp&nbspC# : 0</td>
</tr> <tr>
<td> 박지영 </td>
<td> 40 </td>
Expand Down Expand Up @@ -71,7 +71,7 @@
<td> Python : 12&nbsp&nbsp&nbsp&nbspJava : 0&nbsp&nbsp&nbsp&nbspC : 0&nbsp&nbsp&nbsp&nbsp&nbspC++ : 0&nbsp&nbsp&nbsp&nbsp&nbspC# : 0</td>
</tr></table>
<br>
총 Push 횟수 : 175회
총 Push 횟수 : 177회

# 업로드 방법
### 1. 파일명
Expand Down
2 changes: 1 addition & 1 deletion total_push_cnt.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
175
177

0 comments on commit d1577ea

Please sign in to comment.