Algorithm/Programmers
[Programmers] 코딩테스트 입문 #1 (with Python)
j4ko
2024. 4. 24. 00:16
728x90
반응형
목차
최댓값 만들기(1)
https://school.programmers.co.kr/learn/courses/30/lessons/120847
def solution(numbers):
numbers.sort(reverse=True)
return numbers[0] * numbers[1]
외계행성의 나이
https://school.programmers.co.kr/learn/courses/30/lessons/120834
import string
def solution(age):
alphas = string.ascii_letters[0:10]
age_to_digits = []
while age > 0:
age_to_digits.append(age % 10)
age //= 10
answer = []
while len(age_to_digits) > 0:
answer.append(alphas[age_to_digits.pop()])
return ''.join(answer)
if __name__ == '__main__':
print(solution(23))
순서쌍의 개수
https://school.programmers.co.kr/learn/courses/30/lessons/120836
# 첫 번째 시도 (시간초과)
# def solution(n):
# count = 0
# for i in range(0, n + 1):
# for j in range(0, n + 1):
# if i * j == n:
# count += 1
#
# return count
def solution(n):
number = []
for i in range(1, n+1):
if n % i == 0:
number.append(i)
return len(number)
최댓값 만들기 2
https://school.programmers.co.kr/learn/courses/30/lessons/120862
import sys
def solution(numbers):
current_max = -sys.maxsize
for i1, v1 in enumerate(numbers):
for i2, v2 in enumerate(numbers):
if i1 != i2:
current_max = max(v1 * v2, current_max)
return current_max
if __name__ == '__main__':
print(solution([1, 2, -3, 4, -5]))
print(solution([0, -31, 24, 10, 1, 9]))
print(solution([10, 20, 30, 5, 5, 20, 5]))
369게임
https://school.programmers.co.kr/learn/courses/30/lessons/120891
def solution(order):
count = 0
while order > 0:
if order % 10 == 3 or order % 10 == 6 or order % 10 == 9:
count += 1
order //= 10
return count
자릿수 나누기
def solution(n):
answer = 0
while n > 0:
answer += n % 10
n //= 10
return answer
문자열 안에 문자열
https://school.programmers.co.kr/learn/courses/30/lessons/120908
def solution(str1, str2):
if str2 in str1:
return 1
return 2
진료순서정하기
https://school.programmers.co.kr/learn/courses/30/lessons/120835
def solution(emergency):
hmap = {e: 0 for e in emergency}
rank = 1
for e in sorted(emergency, reverse=True):
hmap[e] = rank
rank += 1
return list(hmap.values())
if __name__ == '__main__':
print(solution([3, 76, 24]))
print(solution([1, 2, 3, 4, 5, 6, 7]))
print(solution([30, 10, 23, 6, 100]))
컨트롤제트
https://school.programmers.co.kr/learn/courses/30/lessons/120853
def solution(s):
lst = s.split(" ")
count = 0
current = 0
for e in lst:
if e != 'Z':
count += int(e)
current = int(e)
if e == "Z":
count -= current
return count
728x90
반응형