Skip to content
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

[230908] PGS 1문제 완료 #111

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
23 changes: 23 additions & 0 deletions JeonHyoChang/Season2/23.08.16 카카오 2문제/실패율.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
def solution(N, stages):
dic = {}
for i in range(1, N + 1):
dic[i] = stages.count(i)

users = len(stages)
answerTemp = []
for i in range(1, N + 1):
if users != 0:
answerTemp.append((dic[i] / users, i))
else:
answerTemp.append((0, i))
users -= dic[i]
print(answerTemp)

answerTemp02 = sorted(answerTemp, key=lambda x: (-x[0], x[1]))
answer = [x[1] for x in answerTemp02]
return answer


print(solution(5, [2, 1, 2, 6, 2, 4, 3, 3]))
print(solution(4, [4, 4, 4, 4, 4]))
print(solution(2, [1, 1, 1, 1]))
34 changes: 34 additions & 0 deletions JeonHyoChang/Season2/23.08.16 카카오 2문제/후보키.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from itertools import combinations


def solution(relation):
row = len(relation)
col = len(relation[0])
relationCombinations = []

for i in range(1, col + 1):
relationCombinations.extend(combinations(range(col), i))

# 유일성 체크
uniqueKeys = []
for x in relationCombinations:
tempSet = set()
for i in range(row):
tempSet.add(tuple(relation[i][j] for j in x))
if len(tempSet) == row:
uniqueKeys.append(x)
print(uniqueKeys)

# 최소성 체크
answer = set(uniqueKeys)
print(answer)
for i in range(len(uniqueKeys)):
for j in range(i + 1, len(uniqueKeys)):
if set(uniqueKeys[i]) & set(uniqueKeys[j]) == set(uniqueKeys[i]):
answer.discard(uniqueKeys[j])

return len(answer)


print(solution([["100", "ryan", "music", "2"], ["200", "apeach", "math", "2"], ["300", "tube", "computer", "3"],
["400", "con", "computer", "4"], ["500", "muzi", "music", "3"], ["600", "apeach", "music", "2"]]))
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def solution(numbers):
answer = set()

for i in range(len(numbers)):
for j in range(i + 1, len(numbers)):
answer.add(numbers[i] + numbers[j])
answer = list(answer)
answer.sort()
return answer


print(solution([2, 1, 3, 4, 1]))
print(solution(([5, 0, 2, 7])))
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
def combine(c, s):
if c != 1:
return str(c) + s
return s


def solution(s):
answer = s

for i in range(1, len(s) // 2 + 1):
tempStr = ""
startStr = s[0:i]
count = 1
for j in range(i, len(s), i):
if s[j:j + i] == startStr:
count += 1
else:
tempStr += combine(count, startStr)
startStr = s[j:j + i]
count = 1
tempStr += combine(count, startStr)
print(tempStr)
if len(answer) > len(tempStr) or i == 1:
answer = tempStr

return len(answer)


# print(solution("aabbaccc"))
# print(solution("ababcdcdababcdcd"))
# print(solution("abcabcdede"))
# print(solution("abcabcabcabcdededededede"))
# print(solution("xababcdcdababcdcd"))
# print(solution("a"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
def solution(sticker):
answer01 = []
answer02 = []

answer01.append(0)
answer02.append(sticker[0])

if len(sticker) > 1:
answer01.append(sticker[1])
answer02.append(sticker[0])

for i in range(2, len(sticker)):
answer01.append(max(answer01[i - 1], answer01[i - 2] + sticker[i]))
answer02.append(max(answer02[i - 1], answer02[i - 2] + sticker[i]))

if len(sticker) == 1:
return sticker[0]
return max(answer01[len(sticker) - 1], answer02[len(sticker) - 2])


print(solution([14, 6, 5, 11, 3, 9, 2, 10]))
25 changes: 25 additions & 0 deletions JeonHyoChang/Season2/23.08.30 카카오 2문제/오픈채팅방.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
def solution(record):
answer = []

userDic = {}
recordChet = []
for x in record:
temp = x.split(" ")
if temp[0] == "Enter" or temp[0] == "Leave":
recordChet.append((temp[0], temp[1]))
if temp[0] != "Leave":
userDic[temp[1]] = temp[2]

for y in recordChet:
tempStr = userDic[y[1]] + "님이 "
if y[0] == "Enter":
answer.append(tempStr + "들어왔습니다.")
else:
answer.append(tempStr + "나갔습니다.")

return answer


print(solution(
["Enter uid1234 Muzi", "Enter uid4567 Prodo", "Leave uid1234", "Enter uid1234 Prodo", "Change uid4567 Ryan"]))

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
def solution(id_list, report, k):
answer = []

reportDic = {}
reportCountDic = {}
for x in id_list:
reportDic[x] = set()
reportCountDic[x] = 0

for y in report:
user = y.split(" ")
reportDic[user[0]].add(user[1])

for z in id_list:
temp = reportDic[z]
for i in temp:
reportCountDic[i] += 1

banSet = set()
for z in id_list:
if reportCountDic[z] >= k:
banSet.add(z)

for z in id_list:
answer.append(len(reportDic[z] & banSet))

return answer


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))