Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypeho committed Aug 19, 2024
2 parents 469871d + c149acb commit 3419e3d
Show file tree
Hide file tree
Showing 26 changed files with 618 additions and 28 deletions.
6 changes: 3 additions & 3 deletions JMRYU/11to20/11.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ def solution(s):
stack = []

for i in s:
if stack and stack[-1] == c:
if stack and stack[-1] == i:
stack.pop()
else:
stack.append(c)
stack.append(i)

return int(not stack)
return int(not stack)
20 changes: 20 additions & 0 deletions JMRYU/11to20/13.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
bucket = []
answer = 0
def solution(board,moves):
lanes = [[]for _ in range(len(board[0]))]

for i in range(len(board) -1, -1, -1):
for j in range(len(board[0])):
if board[i][j]:
lanes[j].append(board[i][j])

for m in moves:
if lanes[m -1]:
doll = lanes[m -1].pop()

if bucket and bucket[-1] == doll:
bucket.pop()
answer += 2
else:
bucket.append(doll)
return answer
34 changes: 34 additions & 0 deletions JMRYU/11to20/14.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
def solution(n, k, cmd):
deleted = [ ]

up = [i - 1 for i in range(n + 2)]

down = [i + 1 for i in range(n + 1)]

k += 1

for cmd_i in cmd:
if cmd_i.startswith("C"):
deleted.append(k)
up[down[k]] = up[k]
down[up[k]] = down[k]
k = up[k] if n < down[k] else down[k]

elif cmd_i.startswith("Z"):
restore = deleted.pop( )
down[up[restore]] = restore
up[down[restore]] = restore

else:
action, num = cmd_i.split( )
if action == "U":
for _ in range(int(num)):
k = up[k]
else:
for _ in range(int(num)):
k = down[k]

answer = ["O"] * n
for i in deleted:
answer[i - 1] = "X"
return "".join(answer)
13 changes: 13 additions & 0 deletions JMRYU/11to20/15.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from collections import deque

def solution(N, K):
que = deque(range(1, N+1))

while len(que)>1:
for _ in range(K -1):
que.append(que.popleft())

que.popleft()
return que[0]

print(solution(5,2))
20 changes: 20 additions & 0 deletions JMRYU/11to20/16.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from collections import deque

def solution(progresses, speeds):
answer = []
days = deque()

for i in range(len(progresses)):
remain = 100 - progresses[i]
day = (remain + speeds[i] - 1) // speeds[i]
days.append(day)

while days:
current_day = days.popleft()
count = 1
while days and days[0] <= current_day:
count += 1
days.popleft()
answer.append(count)

return answer
1 change: 1 addition & 0 deletions JMRYU/1to10/tempCodeRunnerFile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
arr
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@
<td> Python : 31&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> 55 </td>
<td> 55 </td>
<td> 45 </td>
<td> -45000 </td>
<td> Python : 55&nbsp&nbsp&nbsp&nbspJava : 0&nbsp&nbsp&nbsp&nbspC : 0&nbsp&nbsp&nbsp&nbsp&nbspC++ : 0&nbsp&nbsp&nbsp&nbsp&nbspC# : 0</td>
<td> 60 </td>
<td> 60 </td>
<td> 40 </td>
<td> -40000 </td>
<td> Python : 60&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> 12 </td>
<td> 12 </td>
<td> 88 </td>
<td> -88000 </td>
<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>
<td> 16 </td>
<td> 17 </td>
<td> 84 </td>
<td> -84000 </td>
<td> Python : 17&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> 5 </td>
Expand All @@ -51,14 +51,14 @@
<td> Python : 5&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> 32 </td>
<td> 34 </td>
<td> 68 </td>
<td> -68000 </td>
<td> Python : 34&nbsp&nbsp&nbsp&nbspJava : 0&nbsp&nbsp&nbsp&nbspC : 0&nbsp&nbsp&nbsp&nbsp&nbspC++ : 0&nbsp&nbsp&nbsp&nbsp&nbspC# : 0</td>
<td> 45 </td>
<td> 50 </td>
<td> 55 </td>
<td> -55000 </td>
<td> Python : 50&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 횟수 : 143회
총 Push 횟수 : 152회

# 업로드 방법
### 1. 파일명
Expand Down
9 changes: 4 additions & 5 deletions SYCHOI/11to20/tempCodeRunnerFile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
for x in range(10) :
for i in range(len(progresses)) :
if (progresses[i] < 100) :
progresses[i] += speeds[i]
result[i] += 1
k)
print(lst)
print(stack)
print()
30 changes: 30 additions & 0 deletions SYCHOI/21to30/21.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
def solution(want, number, discount) :
dic = {}

# 정현이가 원하는 제품과 개수를 dictionary에 저장
for i in range(len(want)) :
dic[want[i]] = number[i]

# 할인 상품과 원하는 제품 비교
cnt = 0 # 원하는 제품을 모두 할인받을 수 있는 회원 등록 날짜 수
for j in range(len(discount) - 9) : # 10일 순회할 수 있을 만큼만 discount 순회
tenDays = {}

for k in range(j, j + 10) : # 특정 날짜(k)부터 10일간 discount 물품 순회
if discount[k] in dic : # 할인 품목이 정현이가 원하는 제품 목록에 있으면
tenDays[discount[k]] = tenDays.get(discount[k], 0) + 1 # 10일동안 할인받는 물품들의 개수를 tenDays 딕셔너리에 저장
# tenDays에 이미 있으면 해당 값(value) + 1, 없으면 기본값(default value) + 1
if tenDays == dic :
cnt += 1 # 10일 연속으로 원하는 제품을 개수만큼 할인받을 수 있다면 cnt++
break # 책과 다름. 조금 수정함..


return cnt





#TEST 코드입니다. 주석을 풀어서 확인해보세요
print(solution(["banana", "apple", "rice", "pork", "pot"], [3, 2, 2, 2, 1], ["chicken", "apple", "apple", "banana", "rice", "apple", "pork", "banana", "pork", "rice", "pot", "banana", "apple", "banana"]))
print(solution(["apple"], [10], ["banana", "banana", "banana", "banana", "banana", "banana", "banana", "banana", "banana", "banana"]))
85 changes: 85 additions & 0 deletions SYCHOI/21to30/24.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
def solution(id_list, report, k) :
reported_user = {}
count = {}

for r in report :
user_id, reported_id = r.split()
if reported_id not in reported_user :
reported_user[reported_id] = set()
reported_user[reported_id].add(user_id)

for reported_id, user_id_lst in reported_user.items() :
if len(user_id_lst) >= k :
for uid in user_id_lst :
if uid not in count :
count[uid] = 1
else :
count[uid] += 1

answer = []
for i in range(len(id_list)) :
if id_list[i] not in count :
answer.append(0)
else :
answer.append(count[id_list[i]])

return answer


#TEST 코드입니다. 주석을 풀어서 확인해보세요
print(solution(["muzi", "frodo", "apeach", "neo"], ["muzi frodo", "apeach frodo", "frodo neo", "muzi neo", "apeach muzi"], 2))
print(solution(["con", "ryan"], ["ryan con", "ryan con", "ryan con", "ryan con"], 3))










# def solution(id_list, report, k) :
# id_dict = dict.fromkeys(id_list, 0) # 해당 아이디가 신고당한 횟수 기록
# report_dict = {} # 신고자 - 피신고자(리스트 형태) 기록
# mail_dict = dict.fromkeys(id_list, 0) # 신고자가 받을 메일 개수 기록

# for names in report :
# idx = names.split()

# if report_dict.get(idx[0]) == None :
# report_dict[idx[0]] = list()

# if idx[1] not in report_dict[idx[0]] :
# report_dict[idx[0]].append(idx[1])
# id_dict[idx[1]] += 1


# rpt = 0; rpte = 0

# while(1) :
# name = id_list[rpt]

# if report_dict.get(id_dict[name]) == None :
# rpt += 1
# continue
# elif report_dict[id_dict[name]][rpte] >= 2 :
# mail_dict[rpt] += 1

# if report_dict[id_dict[name]][rpte+1] == None :
# rpt = 0
# rpte = 0
# else :
# rpte += 1

# result = list(mail_dict.values())

# print(id_dict)
# print(report_dict)

# return result


# #TEST 코드입니다. 주석을 풀어서 확인해보세요
# print(solution(["muzi", "frodo", "apeach", "neo"], ["muzi frodo", "apeach frodo", "frodo neo", "muzi neo", "apeach muzi"], 2))
# print(solution(["con", "ryan"], ["ryan con", "ryan con", "ryan con", "ryan con"], 3))
28 changes: 28 additions & 0 deletions SYCHOI/21to30/25.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from itertools import combinations
from collections import Counter

def solution(orders, course) :
answer = []

for c in course :
menu = []
for order in orders :
comb = combinations(
sorted(order), c
)
menu += comb
counter = Counter(menu)
if (
len(counter) != 0 and max(counter.values()) != 1
) :
for m, cnt in counter.items() :
if cnt == max(counter.values()) :
answer.append("".join(m))

return sorted(answer)


#TEST 코드입니다. 주석을 풀어서 확인해보세요
print(solution(["ABCFG", "AC", "CDE", "ACDE", "BCFG", "ACDEH"], [2, 3, 4]))
print(solution(["ABCDE", "AB", "CD", "ADE", "XYZ", "XYZ", "ACD"], [2, 3, 5]))
print(solution(["XYZ", "XWY", "WXA"], [2, 3, 4]))
3 changes: 0 additions & 3 deletions SYCHOI/21to30/29.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ def solution(enroll, referral, seller, amount) :







#TEST 코드입니다. 주석을 풀어서 확인해보세요
print(solution(["john", "mary", "edward", "sam", "emily", "jaimie", "tod", "young"], ["-", "-", "mary", "edward", "mary", "mary", "jaimie", "edward"], ["young", "john", "tod", "emily", "mary"], [12, 4, 2, 5, 10]))
Expand Down
2 changes: 2 additions & 0 deletions SYCHOI/21to30/tempCodeRunnerFile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
d(idx[1])
id_dict[idx[1]] += 1
38 changes: 38 additions & 0 deletions SYCHOI/31to40/31.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from collections import deque

def solution(info, edges) :
def build_tree(info, edges) : # 트리 구축 함수
tree = [[] for _ in range(len(info))]
for edge in edges :
tree[edge[0]].append(edge[1])
return tree

tree = build_tree(info, edges) # 트리 생성
max_sheep = 0 # 최대 양의 수를 저장할 변수 초기화

# BFS를 위한 큐 생성 및 초기 상태 설정
q = deque([(0, 1, 0, set())]) # (현재 위치, 양의 수, 늑대의 수, 방문한 노드 집합)

# BFS 시작
while q :
current, sheep_count, wolf_count, visited = q.popleft() # 큐에서 상태 가져오기
max_sheep = max(max_sheep, sheep_count) # 최대 양의 수 업데이트
visited.update(tree[current]) # 방문한 노드 집합에 현재 노드의 이웃 노드 추가

for next_node in visited : # 인접한 노드들에 대해 탐색
if info[next_node] : # 늑대의 경우
if sheep_count != wolf_count + 1 :
q.append(
(next_node, sheep_count, wolf_count + 1, visited - {next_node})
)
else : # 양의 경우
q.append(
(next_node, sheep_count + 1, wolf_count, visited - {next_node})
)

return max_sheep


#TEST 코드입니다. 주석을 풀어서 확인해보세요
print(solution([0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1], [[0, 1], [1, 2], [1, 4], [0, 8], [8, 7], [9, 10], [9, 11], [4, 3], [6, 5], [4, 6], [8, 9]]))
print(solution([0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0], [[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [6, 9], [9, 10]]))
Loading

0 comments on commit 3419e3d

Please sign in to comment.