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
13 changes: 13 additions & 0 deletions silver/programmers/day9/등수 매기기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 1.
# ex. [[80, 70], [90, 50], [40, 70], [50, 80]]

def solution(score):
average = [] # Q. 평균 변수 이름으로 average 괜찮나요?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

굿
avg도 많이 써요

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))
39 changes: 39 additions & 0 deletions silver/programmers/day9/로그인 성공.py
Original file line number Diff line number Diff line change
@@ -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"
11 changes: 3 additions & 8 deletions silver/programmers/day9/문자열 밀기.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
19 changes: 6 additions & 13 deletions silver/programmers/day9/유한소수 판별하기.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 반환
12 changes: 12 additions & 0 deletions silver/programmers/day9/컨트롤 제트.py
Original file line number Diff line number Diff line change
@@ -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)