Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -41,35 +41,35 @@ public static void append(int index, String searchTarget, String[][] given, Stri
}

public static void postOrder(int index, String[] tree) {
if (tree[index] != null && !tree[index].equals(".")) {
if (tree[2*index] != null && !tree[2*index].equals(".")) {
if (tree[index] != null && !tree[index].equals("")) {
if (tree[2*index] != null && !tree[2*index].equals("")) {
postOrder(2*index, tree);

}
if (tree[2*index+1] != null && !tree[2*index+1].equals(".")) {
if (tree[2*index+1] != null && !tree[2*index+1].equals("")) {
postOrder(2*index + 1, tree);
}
System.out.print(tree[index]);
}
}
public static void preOrder(int index, String[] tree) {
if (tree[index] != null && !tree[index].equals(".")) {
if (tree[index] != null && !tree[index].equals("")) {
System.out.print(tree[index]);
if (tree[2*index] != null && !tree[2*index].equals(".")) {
if (tree[2*index] != null && !tree[2*index].equals("")) {
preOrder(2*index, tree);
}
if (tree[2*index+1] != null && !tree[2*index+1].equals(".")) {
if (tree[2*index+1] != null && !tree[2*index+1].equals("")) {
preOrder(2*index + 1, tree);
}
}
}
public static void inOrder(int index, String[] tree) {
if (tree[index] != null && !tree[index].equals(".")) {
if (tree[2*index] != null && !tree[2*index].equals(".")) {
if (tree[index] != null && !tree[index].equals("")) {
if (tree[2*index] != null && !tree[2*index].equals("")) {
inOrder(2*index, tree);
}
System.out.print(tree[index]);
if (tree[2*index+1] != null && !tree[2*index+1].equals(".")) {
if (tree[2*index+1] != null && !tree[2*index+1].equals("")) {
inOrder(2*index + 1, tree);
}
}
Expand Down
File renamed without changes.
46 changes: 46 additions & 0 deletions Gwonwoo-Nam/season2/_230809/뉴스클러스터링.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from collections import defaultdict
import math


def solution(str1, str2):
a = defaultdict(int)
b = defaultdict(int)
for i in range(len(str1) - 1):
st = str1[i:(i + 2)]
if st.isalpha():
a[st.lower()] += 1
for i in range(len(str2) - 1):
st = str2[i:(i + 2)]
if st.isalpha():
b[st.lower()] += 1

if len(b) == 0 and len(a) == 0:
return 65536

com = []
uni = []
# 합집합
# 교집합
for e in a.keys():
if e in b.keys():
# 교집합인 경우
for i in range(min(a[e], b[e])) :
com.append(e)
for i in range(max(a[e], b[e])) :
uni.append(e)
else:
# A에만 소속
for i in range(a[e]):
uni.append(e)
for e in b:
if e not in a:
# B에만 소속
for i in range(b[e]):
uni.append(e)
print(uni, com)

answer = 65536 * len(com) / len(uni)
return math.floor(answer)


solution( "aa1+aa2", "AAAA12")
50 changes: 50 additions & 0 deletions Gwonwoo-Nam/season2/_230809/다트게임.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from collections import deque

def solution(dartResult):
answer = 0


li = deque(dartResult)
maps = [[0 for i in range(3)] for j in range(3)]

i = 0

# maps[0][0] = 0~10, maps[0][1] = S, D, T, maps[0][2] = *, #, null
while li :
if li :
e = li.popleft();
if e.isdigit() :
if len(li) > 0 and li[0].isdigit() :
maps[i][0] = (int(e)*10 + int(li.popleft()))
else :
maps[i][0] = int(e)

if li :
if li[0] in ("S", "D", "T") :
maps[i][1] = li.popleft()
if li :
if li[0] in ("*", "#") :
maps[i][2] = li.popleft()
i+=1

for i in range(3) :

bonus = maps[i][1]
option = maps[i][2]

if bonus == "D" :
maps[i][0] *= maps[i][0]
elif bonus == "T" :
maps[i][0] = maps[i][0]*maps[i][0]*maps[i][0]
if option == "#" :
maps[i][0] *= -1
elif option == "*" :
maps[i][0] *= 2
if i>= 1 :
maps[i-1][0] *= 2

for i in range(3) :
answer += maps[i][0]


return answer
29 changes: 29 additions & 0 deletions Gwonwoo-Nam/season2/_230830/스티커모으기2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
def solution(sticker):
answer = 0


if len(sticker) == 1 :
return sticker[0]
# 첫번째 스티커를 뜯는 경우와 뜯지 않는 경우로 나눈다.

# 뜯는 경우(마지막 인덱스를 뜯지 못한다.)
dp = [0 for i in range(len(sticker))]
dp[0] = sticker[0]
dp[1] = sticker[0]
for i in range(2, len(sticker) - 1) :
dp[i] = max(dp[i-1], dp[i-2] + sticker[i])

# 뜯지 않는 경우(마지막 인덱스를 뜯을 수 있다.)
dp2 = [0 for i in range(len(sticker))]
dp2[0] = 0
dp2[1] = sticker[1]
for i in range(2, len(sticker)) :
dp2[i] = max(dp2[i-1], dp2[i-2] + sticker[i])

for e in dp :
answer = max(answer, e)
for e in dp2 :
answer = max(answer, e)


return max(dp[len(sticker)-2], dp2[len(sticker)-1])
32 changes: 32 additions & 0 deletions Gwonwoo-Nam/season2/_230830/오픈채팅방.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
def solution(record):
answer = []

# user_id를 key로 가지는 dict

user_dict = {}
for e in record :
splits = e.split()
if len(splits) > 2 :
command, user_id, nick_name = splits
else :
command, user_id = splits

if command == "Enter" :
user_dict[user_id] = nick_name
elif command == "Change" :
user_dict[user_id] = nick_name

for e in record :
splits = e.split()
if len(splits) > 2 :
command, user_id, nick_name = splits
else :
command, user_id = splits

if command == "Enter" :
answer.append(user_dict[user_id] + "님이 들어왔습니다.")

elif command == "Leave" :
answer.append(user_dict[user_id] + "님이 나갔습니다.")

return answer