From 994b99a28ab44043436a8d7cf8222e739370ad22 Mon Sep 17 00:00:00 2001 From: eunbillee Date: Wed, 23 Nov 2022 01:45:21 +0900 Subject: [PATCH 1/5] =?UTF-8?q?question=5F=EB=93=B1=EC=88=98=20=EB=A7=A4?= =?UTF-8?q?=EA=B8=B0=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...210\230 \353\247\244\352\270\260\352\270\260.py" | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 "silver/programmers/day9/\353\223\261\354\210\230 \353\247\244\352\270\260\352\270\260.py" diff --git "a/silver/programmers/day9/\353\223\261\354\210\230 \353\247\244\352\270\260\352\270\260.py" "b/silver/programmers/day9/\353\223\261\354\210\230 \353\247\244\352\270\260\352\270\260.py" new file mode 100644 index 0000000..2333d0f --- /dev/null +++ "b/silver/programmers/day9/\353\223\261\354\210\230 \353\247\244\352\270\260\352\270\260.py" @@ -0,0 +1,13 @@ +# 1. +# ex. [[80, 70], [90, 50], [40, 70], [50, 80]] + +def solution(score): + average = [] # Q. 평균 변수 이름으로 average 괜찮나요? + answer = [] + for grade in score: + average.append(sum(grade) // len(grade)) + average = sorted(average, reverse=True) + # print(average) : [75, 70, 65, 55] + for grade in score: + answer.append(average.index(sum(grade) // len(grade))) # Q. [[1, 2], [1, 1], [1, 1]] : [1, 1, 1]을 어떻게 처리할지 궁금합니다. + return [idx + 1 for idx in answer] # = list(map(lambda idx: idx + 1, answer)) \ No newline at end of file From 31118b904d2dfa4cb09b56a297c35d4a23caa8ab Mon Sep 17 00:00:00 2001 From: eunbillee Date: Wed, 23 Nov 2022 01:45:43 +0900 Subject: [PATCH 2/5] =?UTF-8?q?solve=5F=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EC=84=B1=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\354\235\270 \354\204\261\352\263\265.py" | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 "silver/programmers/day9/\353\241\234\352\267\270\354\235\270 \354\204\261\352\263\265.py" diff --git "a/silver/programmers/day9/\353\241\234\352\267\270\354\235\270 \354\204\261\352\263\265.py" "b/silver/programmers/day9/\353\241\234\352\267\270\354\235\270 \354\204\261\352\263\265.py" new file mode 100644 index 0000000..83e5a74 --- /dev/null +++ "b/silver/programmers/day9/\353\241\234\352\267\270\354\235\270 \354\204\261\352\263\265.py" @@ -0,0 +1,39 @@ +# 1. +# keypoint +# 1차원 배열 in/not in 2차원 배열 (O) +# but, 1차원 배열의 요소 in/not in 2차원 배열 (X) +# ex. id_pw[0] in db (X) +# ex. id_pw[0] in db[0] (O) + +def solution(id_pw, db): + answer = ["login", "wrong pw", "fail"] + if id_pw in db: + return answer[0] + else: + for idx in range(len(db)): + if id_pw[0] in db[idx]: + if id_pw[1] not in db[idx]: + return answer[1] + return answer[2] + +# 2. +def solution(id_pw, db): + if db_pw := dict(db).get(id_pw[0]): # Q. + return "login" if db_pw == id_pw[1] else "wrong pw" + return "fail" + +# 3. +# ex. id_pw, db +# ["meosseugi", "1234"], [["rardss", "123"], ["yyoom", "1234"], ["meosseugi", "1234"]] + +def solution(id_pw, db): + answer = '' + a, b = id_pw[0], id_pw[1] + for pk, pw in db: + # print(pk,pw) : rardss 123 yyoom 1234 meosseugi 1234 + if pk == a and pw == b: + return "login" + for pk, pw in db: + if pk == a: + return "wrong pw" + return "fail" \ No newline at end of file From afb93c717bd4f470ccd6ca95cda4a3f844dbc5cc Mon Sep 17 00:00:00 2001 From: eunbillee Date: Wed, 23 Nov 2022 01:45:52 +0900 Subject: [PATCH 3/5] =?UTF-8?q?solve=5F=EB=AC=B8=EC=9E=90=EC=97=B4=20?= =?UTF-8?q?=EB=B0=80=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\236\220\354\227\264 \353\260\200\352\270\260.py" | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git "a/silver/programmers/day9/\353\254\270\354\236\220\354\227\264 \353\260\200\352\270\260.py" "b/silver/programmers/day9/\353\254\270\354\236\220\354\227\264 \353\260\200\352\270\260.py" index 8b0ad2d..e9fb05d 100644 --- "a/silver/programmers/day9/\353\254\270\354\236\220\354\227\264 \353\260\200\352\270\260.py" +++ "b/silver/programmers/day9/\353\254\270\354\236\220\354\227\264 \353\260\200\352\270\260.py" @@ -3,20 +3,15 @@ # ex. A + A = hellohello # ex. A * 2 = hellohello -# 1. Why not? def solution(A, B): - answer = '' - + if A == B: + return 0 for i in range(1, len(A) + 1): if A[-i:] + A[0:-i] == B: # print(A[-1:], A[0:-1]) → o hell - print(A[-2:], A[0:-2]) # print(A[-2:], A[0:-2]) → lo hel return i - elif A == B: - return 0 - else: - return -1 + return -1 # for문의 첫 반복 뿐만 아니라 모든 반복을 거친 후에도, B가 될 수 없으면 -1 반환 # 2. def solution(A, B): From d0694278df9fbb814282ab6e34d88509de429934 Mon Sep 17 00:00:00 2001 From: eunbillee Date: Wed, 23 Nov 2022 01:46:03 +0900 Subject: [PATCH 4/5] =?UTF-8?q?solve=5F=EC=9C=A0=ED=95=9C=EC=86=8C?= =?UTF-8?q?=EC=88=98=20=ED=8C=90=EB=B3=84=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...20\353\263\204\355\225\230\352\270\260.py" | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git "a/silver/programmers/day9/\354\234\240\355\225\234\354\206\214\354\210\230 \355\214\220\353\263\204\355\225\230\352\270\260.py" "b/silver/programmers/day9/\354\234\240\355\225\234\354\206\214\354\210\230 \355\214\220\353\263\204\355\225\230\352\270\260.py" index 7cdd637..6819b7c 100644 --- "a/silver/programmers/day9/\354\234\240\355\225\234\354\206\214\354\210\230 \355\214\220\353\263\204\355\225\230\352\270\260.py" +++ "b/silver/programmers/day9/\354\234\240\355\225\234\354\206\214\354\210\230 \355\214\220\353\263\204\355\225\230\352\270\260.py" @@ -5,16 +5,9 @@ import math def solution(a, b): - # 분자/분모의 최대공약수 구하기 - a_b = math.gcd(a, b) - - # 분자를 최대공약수로 약분 - a = a // a_b - - # 분모를 최대공약수로 약분 - b = b // a_b - - if (b % 2 == 0 or b % 5 == 0) or (a % b == 0): # 분자의 소인수가 2 or 5만 있다는 것을 어떻게 확인? - return 1 - else: - return 2 \ No newline at end of file + b //= math.gcd(a,b) # 분자, 분모의 최대공약수로 분모를 약분하여 기약분수로 만들기 + while b % 2 == 0: # 1) 분모가 2로 나눠질 때까지 + b //= 2 # 2로 나누는 과정 반복 + while b % 5 == 0: # 2) 2로 나눌 때까지 나눈 후, 5로 나눠질 때까지 + b //= 5 # 5로 나누는 과정 반복 + return 1 if b == 1 else 2 # 분모의 남은 약수가 1이라면 1, 아니라면 2 반환 \ No newline at end of file From 8fd3f34160abdf41d6b47253dcd7ef403b752bdf Mon Sep 17 00:00:00 2001 From: eunbillee Date: Wed, 23 Nov 2022 01:46:13 +0900 Subject: [PATCH 5/5] =?UTF-8?q?solve=5F=EC=BB=A8=ED=8A=B8=EB=A1=A4=20?= =?UTF-8?q?=EC=A0=9C=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\212\270\353\241\244 \354\240\234\355\212\270.py" | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 "silver/programmers/day9/\354\273\250\355\212\270\353\241\244 \354\240\234\355\212\270.py" diff --git "a/silver/programmers/day9/\354\273\250\355\212\270\353\241\244 \354\240\234\355\212\270.py" "b/silver/programmers/day9/\354\273\250\355\212\270\353\241\244 \354\240\234\355\212\270.py" new file mode 100644 index 0000000..679d1a4 --- /dev/null +++ "b/silver/programmers/day9/\354\273\250\355\212\270\353\241\244 \354\240\234\355\212\270.py" @@ -0,0 +1,12 @@ +# 1. +# keypoint +# Z 바로 전 값 = 마지막 값 제거 : pop() + +def solution(s): + answer = [] + for i in s.split(): # for문에 split() 즉시 적용 가능 + if i == "Z": + answer.pop() + else: + answer.append(int(i)) # str → int 즉시 적용 가능 + return sum(answer) \ No newline at end of file