From e275b3a7d8ad9a19116aaf9b99432e805b7436a0 Mon Sep 17 00:00:00 2001 From: SongheeNoh Date: Fri, 7 Oct 2022 16:20:27 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[Line]=202,=203=EB=B2=88=20=EC=8B=9C?= =?UTF-8?q?=EB=8F=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SH_Noh/season3/CodingTest/Line/2.py | 35 +++++++++++++++++++---------- SH_Noh/season3/CodingTest/Line/3.py | 6 ++++- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/SH_Noh/season3/CodingTest/Line/2.py b/SH_Noh/season3/CodingTest/Line/2.py index 5fcc25e..9651653 100644 --- a/SH_Noh/season3/CodingTest/Line/2.py +++ b/SH_Noh/season3/CodingTest/Line/2.py @@ -3,21 +3,32 @@ def filtering(k, dic, string): if string in dic: string = "#" * len(string) - if "." in string: + return string + # .이 대체할 수 있는 만큼 word에서 빼자 + if "." in string: # ex) bad.ord + # .이 들어갈 수 있는 단어가 최대로 커버할 수 있는 길이 + max_len = len(string) + string.count(".") * (k - 1) # 8 for word in dic: - for i in range(len(word)): - for j in range(len(string)): - if i == j: - pass - elif i == ".": - string[j] = word[i] - else: - continue - return string + # 커버할 수 없는 길이면 return + if len(word) > max_len: + return string + else: + for i in range(len(word)): + for j in range(max_len): + if word[i] == string[j]: + continue + if string[j] == ".": + string[j] = word[i] + else: + continue def solution(k: int, dic: List[str], chat: str) -> str: - answer = '' chat = chat.split(" ") for i in range(len(chat)): chat[i] = filtering(k, dic, chat[i]) - return " ".join(chat) \ No newline at end of file + return " ".join(chat) + +# print(solution(2, ["slang", "badword"], "badword ab.cd bad.ord .word sl.. bad.word")) +print(solution(2, ["slang", "badword"], "bad.ord")) +# print(solution(3, ["abcde", "cdefg", "efgij"], ".. ab. cdefgh .gi. .z.")) +print(solution(3, ["abcde", "cdefg", "efgij"], "ab.")) \ No newline at end of file diff --git a/SH_Noh/season3/CodingTest/Line/3.py b/SH_Noh/season3/CodingTest/Line/3.py index 3a370ec..c7c788e 100644 --- a/SH_Noh/season3/CodingTest/Line/3.py +++ b/SH_Noh/season3/CodingTest/Line/3.py @@ -48,4 +48,8 @@ def solution(n: int, m: int, fires: List[List[int]], ices: List[List[int]]) -> L # print(answer) ices, answer = icing(ices, answer, n) print(answer) - return answer \ No newline at end of file + return answer + +print(solution(3, 2, [[1, 1]], [[3, 3]])) +# [[2, 2, 0], [2, 1, -1], [0, -1, -1]] +print(solution(5, 3, [[5, 5], [1, 3], [5, 2]], [[1, 5], [3, 2]])) \ No newline at end of file From 8be0420a7d8a9c6b2f02bf7c639825d3eca2840f Mon Sep 17 00:00:00 2001 From: SongheeNoh Date: Sat, 15 Oct 2022 20:16:26 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[baekjoon-9375]=20=ED=8C=A8=EC=85=98?= =?UTF-8?q?=EC=99=95=20=EC=8B=A0=ED=95=B4=EB=B9=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...25\354\213\240\355\225\264\353\271\210.py" | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 "SH_Noh/season3/baekjoon/10/03-2/9375_\355\214\250\354\205\230\354\231\225\354\213\240\355\225\264\353\271\210.py" diff --git "a/SH_Noh/season3/baekjoon/10/03-2/9375_\355\214\250\354\205\230\354\231\225\354\213\240\355\225\264\353\271\210.py" "b/SH_Noh/season3/baekjoon/10/03-2/9375_\355\214\250\354\205\230\354\231\225\354\213\240\355\225\264\353\271\210.py" new file mode 100644 index 0000000..a0be048 --- /dev/null +++ "b/SH_Noh/season3/baekjoon/10/03-2/9375_\355\214\250\354\205\230\354\231\225\354\213\240\355\225\264\353\271\210.py" @@ -0,0 +1,19 @@ +from sys import stdin +input = stdin.readline + +T = int(input()) +for _ in range(T): + clothes = int(input()) + cloth_dict = {} + for _ in range(clothes): + cloth, type = input().split() + if type in cloth_dict: + cloth_dict[type] += 1 + else: + cloth_dict[type] = 1 + # 해당 종류를 입을지 안입을지 모든 경우의 수 곱하기 + answer = 1 + for type in cloth_dict: + answer *= cloth_dict[type] + 1 + # 알몸이 되는 경우 빼기 + print(answer - 1) From 834c384dcc81ab0d0eb67589cadd964624ab91eb Mon Sep 17 00:00:00 2001 From: SongheeNoh Date: Sat, 15 Oct 2022 20:16:40 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[baekjoon-1107]=20=EB=A6=AC=EB=AA=A8?= =?UTF-8?q?=EC=BB=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...7_\353\246\254\353\252\250\354\273\250.py" | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 "SH_Noh/season3/baekjoon/10/03-2/1107_\353\246\254\353\252\250\354\273\250.py" diff --git "a/SH_Noh/season3/baekjoon/10/03-2/1107_\353\246\254\353\252\250\354\273\250.py" "b/SH_Noh/season3/baekjoon/10/03-2/1107_\353\246\254\353\252\250\354\273\250.py" new file mode 100644 index 0000000..8e9fb9c --- /dev/null +++ "b/SH_Noh/season3/baekjoon/10/03-2/1107_\353\246\254\353\252\250\354\273\250.py" @@ -0,0 +1,37 @@ +# https://www.acmicpc.net/board/view/73355 +from itertools import product +from sys import stdin +input = stdin.readline + +# 현재 100번에서 시작 +# 먼저 제일 가까운 숫자를 찾아야 함 +def main(): + channel_num = int(input()) + broken = int(input()) + length = len(str(channel_num)) + if broken == 0: + print(min(length, abs(channel_num - 100))) + else: + # 일단 answer에 100번과의 차이를 저장 + answer = abs(channel_num - 100) if channel_num != 100 else 0 + + broken_nums = set(input().split()) + nums = set(["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]) + normal_nums = nums - broken_nums + + # 가능한 조합 중 원하는 채널보다 하나 작은 개수, 같은 개수, 하나 많은 개수의 길이인 경우 구하기 + possible_nums = [] + if length == 1: + for x in range(length, length + 2): + possible_nums.extend(product(normal_nums, repeat = x)) + else: + for x in range(length - 1, length + 2): + possible_nums.extend(product(normal_nums, repeat = x)) + + for y in possible_nums: + num = int("".join(y)) + if abs(channel_num - num) + len(y) < answer: + answer = abs(channel_num - num) + len(y) + print(answer) + +main() \ No newline at end of file