diff --git "a/JeonHyoChang/Season2/23.08.16 \354\271\264\354\271\264\354\230\244 2\353\254\270\354\240\234/\354\213\244\355\214\250\354\234\250.py" "b/JeonHyoChang/Season2/23.08.16 \354\271\264\354\271\264\354\230\244 2\353\254\270\354\240\234/\354\213\244\355\214\250\354\234\250.py" new file mode 100644 index 0000000..0de4294 --- /dev/null +++ "b/JeonHyoChang/Season2/23.08.16 \354\271\264\354\271\264\354\230\244 2\353\254\270\354\240\234/\354\213\244\355\214\250\354\234\250.py" @@ -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])) diff --git "a/JeonHyoChang/Season2/23.08.16 \354\271\264\354\271\264\354\230\244 2\353\254\270\354\240\234/\355\233\204\353\263\264\355\202\244.py" "b/JeonHyoChang/Season2/23.08.16 \354\271\264\354\271\264\354\230\244 2\353\254\270\354\240\234/\355\233\204\353\263\264\355\202\244.py" new file mode 100644 index 0000000..47bdd2d --- /dev/null +++ "b/JeonHyoChang/Season2/23.08.16 \354\271\264\354\271\264\354\230\244 2\353\254\270\354\240\234/\355\233\204\353\263\264\355\202\244.py" @@ -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"]])) diff --git "a/JeonHyoChang/Season2/23.08.25 \354\271\264\354\271\264\354\230\244 2\353\254\270\354\240\234/\353\221\220 \352\260\234 \353\275\221\354\225\204\354\204\234 \353\215\224\355\225\230\352\270\260.py" "b/JeonHyoChang/Season2/23.08.25 \354\271\264\354\271\264\354\230\244 2\353\254\270\354\240\234/\353\221\220 \352\260\234 \353\275\221\354\225\204\354\204\234 \353\215\224\355\225\230\352\270\260.py" new file mode 100644 index 0000000..59ffb60 --- /dev/null +++ "b/JeonHyoChang/Season2/23.08.25 \354\271\264\354\271\264\354\230\244 2\353\254\270\354\240\234/\353\221\220 \352\260\234 \353\275\221\354\225\204\354\204\234 \353\215\224\355\225\230\352\270\260.py" @@ -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]))) diff --git "a/JeonHyoChang/Season2/23.08.25 \354\271\264\354\271\264\354\230\244 2\353\254\270\354\240\234/\353\254\270\354\236\220\354\227\264 \354\225\225\354\266\225.py" "b/JeonHyoChang/Season2/23.08.25 \354\271\264\354\271\264\354\230\244 2\353\254\270\354\240\234/\353\254\270\354\236\220\354\227\264 \354\225\225\354\266\225.py" new file mode 100644 index 0000000..47929b3 --- /dev/null +++ "b/JeonHyoChang/Season2/23.08.25 \354\271\264\354\271\264\354\230\244 2\353\254\270\354\240\234/\353\254\270\354\236\220\354\227\264 \354\225\225\354\266\225.py" @@ -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")) diff --git "a/JeonHyoChang/Season2/23.08.30 \354\271\264\354\271\264\354\230\244 2\353\254\270\354\240\234/\354\212\244\355\213\260\354\273\244\353\252\250\354\234\274\352\270\260(2).py" "b/JeonHyoChang/Season2/23.08.30 \354\271\264\354\271\264\354\230\244 2\353\254\270\354\240\234/\354\212\244\355\213\260\354\273\244\353\252\250\354\234\274\352\270\260(2).py" new file mode 100644 index 0000000..b967826 --- /dev/null +++ "b/JeonHyoChang/Season2/23.08.30 \354\271\264\354\271\264\354\230\244 2\353\254\270\354\240\234/\354\212\244\355\213\260\354\273\244\353\252\250\354\234\274\352\270\260(2).py" @@ -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])) diff --git "a/JeonHyoChang/Season2/23.08.30 \354\271\264\354\271\264\354\230\244 2\353\254\270\354\240\234/\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.py" "b/JeonHyoChang/Season2/23.08.30 \354\271\264\354\271\264\354\230\244 2\353\254\270\354\240\234/\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.py" new file mode 100644 index 0000000..a0c4416 --- /dev/null +++ "b/JeonHyoChang/Season2/23.08.30 \354\271\264\354\271\264\354\230\244 2\353\254\270\354\240\234/\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.py" @@ -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"])) + diff --git "a/JeonHyoChang/Season2/23.09.08 \354\271\264\354\271\264\354\230\244 1\353\254\270\354\240\234/\354\213\240\352\263\240 \352\262\260\352\263\274 \353\260\233\352\270\260.py" "b/JeonHyoChang/Season2/23.09.08 \354\271\264\354\271\264\354\230\244 1\353\254\270\354\240\234/\354\213\240\352\263\240 \352\262\260\352\263\274 \353\260\233\352\270\260.py" new file mode 100644 index 0000000..c8b9d9e --- /dev/null +++ "b/JeonHyoChang/Season2/23.09.08 \354\271\264\354\271\264\354\230\244 1\353\254\270\354\240\234/\354\213\240\352\263\240 \352\262\260\352\263\274 \353\260\233\352\270\260.py" @@ -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))