Algorithm/Programmers

[Programmers] 코딩 기초 트레이닝 #3

j4ko 2023. 11. 25. 02:24
728x90
반응형

 

목차

     

    배열의 길이에 따라 다른 연산하기

    https://school.programmers.co.kr/learn/courses/30/lessons/181854

    def solution(arr, n):
        LENGTH = len(arr)
    
        update_index = []
    
        if LENGTH % 2 != 0:
            for x in range(0, LENGTH):
                if x % 2 == 0:
                    update_index.append(x)
        else:
            for x in range(0, LENGTH):
                if x % 2 != 0:
                    update_index.append(x)
    
        for index in update_index:
            arr[index] = arr[index] + n
            
        return arr

     

    더 크게 합치기

    https://school.programmers.co.kr/learn/courses/30/lessons/181939

    def solution(a, b):
        ex1 = int(str(a)+str(b))
        ex2 = int(str(b)+str(a))
        
        return  ex1 if ex1 > ex2 else ex2

     

    문자열 곱하기

    https://school.programmers.co.kr/learn/courses/30/lessons/181940

    def solution(my_string, k):
        return my_string * k
    

     

    n번째 원소부터

    https://school.programmers.co.kr/learn/courses/30/lessons/181892

    def solution(num_list, n):
        return num_list[n-1::]
    

     

    수 조작하기 1

    https://school.programmers.co.kr/learn/courses/30/lessons/181926

    def solution(n, control):
        m = {"w": 1,"s": -1,"d": +10,"a": -10}
    
        for c in control:
            n = n + m[c]
    
        return n
    

     

    조건에 맞게 수 변환하기

    https://school.programmers.co.kr/learn/courses/30/lessons/181835

    def solution(arr, k):
        if k % 2 != 0 :
            return [a *k for a in arr] 
        else:
            return [a +k for a in arr]
    

     

    홀짝 구분하기

    https://school.programmers.co.kr/learn/courses/30/lessons/181944

    a = int(input())
    
    if a % 2 == 0:
        print(a, "is even")
    else:
        print(a, "is odd")
    

     

    글자 이어 붙여 만들기

    https://school.programmers.co.kr/learn/courses/30/lessons/181915

    def solution(my_string, index_list):
        
        answer = ""
        for index in index_list:
            answer += my_string[index]
                
        return answer
    

     

    배열 만들기

    https://school.programmers.co.kr/learn/courses/30/lessons/181901

    def solution(n, k):
        answer = []
        for x in range(1, n+1):
            if x % k == 0:
                answer.append(x)            
        
        return answer

     

    배열의 원소만큼 추가하기

    https://school.programmers.co.kr/learn/courses/30/lessons/181861

    def solution(arr):
        answer = []
        for a in arr:
            for x in range(0, a):
                answer.append(a)
            
        return answer
    728x90
    반응형