문제 : 옷가게 할인받기
https://school.programmers.co.kr/learn/courses/30/lessons/120818
프로그래머스
SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
내 코드:
# 1. 마지막 else를 안써서 10만원 미만일 때 값이 0으로 출력되던 에러
# 2. 소숫점을 곱하니까 출력이 float으로 나오던 에러
def solution(price):
answer = 0
if price >= 500000:
answer = int(price*0.8)
elif price >= 300000:
answer = int(price*0.9)
elif price >= 100000:
answer = int(price * 0.95)
else:
answer = price
return answer
좋은 코드:
def solution(price):
discount_rates = {500000: 0.8, 300000: 0.9, 100000: 0.95, 0: 1}
for discount_price, discount_rate in discount_rates.items():
if price >= discount_price:
return int(price * discount_rate)
def solution(price):
return (100 - len([1 for k in [100000, 300000, 500000, 500000] if k<=price])*5) * price // 100
문제 : 아이스 아메리카노
https://school.programmers.co.kr/learn/courses/30/lessons/120819
프로그래머스
SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
내 코드:
def solution(money):
answer = []
americano = 5500
answer.append(money//americano)
answer.append(money%americano)
return answer
좋은 코드:
def solution(money):
answer = [money // 5500, money % 5500]
return answer
def solution(money):
return divmod(money, 5500)
def solution(money):
cup = money//5500
change = money%5500
return [cup, change]
# 이건 math 사용 했는데 독특해서
import math
def kake(a, b):
res = 0
while (b > 0):
if (b & 1):res = res + a
a = a << 1
b = b >> 1
return res
def wari(w1, w2):
ans = math.exp(math.log(abs(w1)) - math.log(abs(w2))) + 0.0000000001
return math.trunc(ans)
def solution(money):
return [wari(money, 5500), money + ~(kake(5500, wari(money, 5500))) + 0x1]
문제: 나이 출력
https://school.programmers.co.kr/learn/courses/30/lessons/120820
프로그래머스
SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
내 코드:ㅣ
def solution(age):
answer = 2022-age+1
return answer
특이한 코드:
def solution(age):
import datetime
return datetime.datetime.utcnow().year - age + 1
문제: 배열 뒤집기 ⭐️⭐️⭐️
https://school.programmers.co.kr/learn/courses/30/lessons/120821
프로그래머스
SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
내 코드:
맨 앞에 원소 추가하기
my_list = [2, 3, 4]
my_list.insert(0, 1)
def solution(num_list):
answer = []
for i in num_list:
answer.insert(0, i)
return answer
좋은코드:
# 내가 하고 싶었던 코드는 이거였는데 기억을 못해서 못함
# 시작과 끝 -- 처음부터 끝까지 전체 불러오고
# 역방향으로 1칸씩 이동하며 요소를 가져오는 것
def solution(num_list):
return num_list[::-1]
def solution(num_list):
result =[]
while(num_list):
result.append(num_list.pop())
return result
def solution(num_list):
num_list.reverse()
return num_list
from collections import deque
def solution(num_list):
answer = deque([])
for i in num_list:
answer.appendleft(i)
return list(answer)
def solution(num_list):
answer = []
for i in range(1,len(num_list)+1):
answer.append(num_list[-i])
return answer
def solution(num_list):
answer = []
print(num_list)
for i in range(len(num_list)):
answer.append(num_list[-i-1])
return answer
'카테부 4기 판교 ai 실무 > 코테 공부' 카테고리의 다른 글
| [⭐ 꼭 다시보기⭐] 프로그래머스 코딩테스트 "입문 문제" Day4 (0) | 2026.06.24 |
|---|---|
| 프로그래머스 코딩테스트 "입문 문제" Day3 (0) | 2026.06.23 |
| [⭐ 꼭 다시보기⭐] 프로그래머스 코딩테스트 "입문 문제" Day2 (0) | 2026.06.22 |
| 프로그래머스 코딩테스트 "입문 문제" Day1 (0) | 2026.06.20 |
| [⭐ 꼭 다시보기⭐] 카테부 4기 판교 ai 실무프로그래머스 코딩 기초 트레이닝 Day25 (0) | 2026.06.19 |