프로그래머스 LV 1(2)

2024. 1. 25. 19:46백준 및 프로그래머스/프로그래머스 LV 1

-서울에서 김서방 찾기

def solution(seoul):
    answer = ''
    for i in range(len(seoul)):
        if seoul[i] =='Kim':
            answer+=f"김서방은 {i}에 있다"
    return answer

 

 

-나누어 떨어지는 배열

def solution(arr, divisor):
    answer = []
    for i in range(len(arr)):
        if arr[i] % divisor == 0:
            answer.append(arr[i])
    answer.sort()
    
    if len(answer) == 0:
        return [-1]
    
    else:
        return answer

 

-없는 숫자 더하기

def solution(numbers):
    answer = 0
    num = [1,2,3,4,5,6,7,8,9]
    
    answer = sum(num) - sum(numbers)
            
    return answer

 

-핸드폰 번호 가리기

def solution(phone_number):
    answer = ''
    for i in range(len(phone_number)-4):
        answer+="*"
    answer+=phone_number[-4:]
    return answer

 

-제일 작은 수 제거하기

def solution(arr):
    answer = []
    if len(arr) == 1:
        return [-1]
    
    else:
        tal = arr[0]
        
        for i in arr:
            if i < tal:
                tal = i
        arr.remove(tal)
        return arr

'백준 및 프로그래머스 > 프로그래머스 LV 1' 카테고리의 다른 글

프로그래머스 LV 1  (0) 2024.01.28
프로그래머스 LV 1(5)  (0) 2024.01.26
프로그래머스 LV1(4)  (0) 2024.01.26
프로그래머스 LV1(3)  (2) 2024.01.26
프로그래머스 1LV (1)  (0) 2024.01.25