Algorithm/Programmers
[Programers] 코딩테스트 입문 #6 (with Python)
j4ko
2024. 5. 1. 23:02
728x90
반응형
목차
커피심부름
https://school.programmers.co.kr/learn/courses/30/lessons/181837
def solution(order):
total = 0
for x in order:
if x.find("americano") != -1:
total += 4500
if x.find('cafelatte') != -1:
total += 5000
if x.find('anything') != -1:
total += 4500
return total
if __name__ == '__main__':
print(solution(order=["cafelatte", "americanoice", "hotcafelatte", "anything"]))
왼쪽 오른쪽
https://school.programmers.co.kr/learn/courses/30/lessons/181890
def solution(str_list):
answer = []
for idx, value in enumerate(str_list):
if value == 'l':
answer = str_list[:idx]
break
if value == 'r':
answer = str_list[idx+1:]
break
return answer
if __name__ == '__main__':
print(solution(["u", "u", "l", "r"]))
print(solution(["l"]))
print(solution(["u", "r", "u", "r"]))
print(solution(["r", "l"]))
print(solution(["u", "u", "r", "l", "r", "r", "r", "r"]))
조건에 맞게 수열 반환하기2
https://school.programmers.co.kr/learn/courses/30/lessons/181881
def solution(arr):
latest = arr
count = 0
for _ in range(len(arr)):
_temp = []
for idx, value in enumerate(latest):
if value >= 50 and value % 2 == 0:
t = value / 2
elif value < 50 and value % 2 != 0:
t = (value * 2) + 1
else:
t = value
_temp.append(int(t))
if latest != _temp:
latest = _temp
count += 1
else:
break
return count
if __name__ == '__main__':
print(solution(arr=[1, 2, 3, 100, 99, 98]))
728x90
반응형