Algorithm/Programmers

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

j4ko 2023. 12. 2. 02:01
728x90
반응형

목차

    배열 만들기 3

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

    def solution(arr, intervals):
        answer = []
    
        for x in intervals:
            start, end = tuple(x)
            answer.extend(arr[start:end + 1])
        return answer
    

     

    문자 리스트를 문자열로 변환하기

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

    def solution(arr):
        return ''.join(arr)
    

    문자열 돌리기

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

    str = input()
    for x in str:
        print(x)
    

     

    주사위 게임2

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

    def solution(a, b, c):
        hmap = {str(x): 0 for x in range(1, 7)}
    
        for n in [str(a), str(b), str(c)]:
            hmap[n] += 1
    
        count = 0
        for i, v in hmap.items():
            if v != 0:
                count += 1
    
        if count == 3:
            return a + b + c
        if count == 2:
            return (a + b + c) * (a ** 2 + b ** 2 + c ** 2)
        if count == 1:
            return (a + b + c) * (a ** 2 + b ** 2 + c ** 2) * (a ** 3 + b ** 3 + c ** 3)
    

     

    9로 나눈 나머지

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

    def solution(number):
        sum_number = sum([int(x) for x in ''.join(number)])
        return sum_number % 9
    

     

    세로 읽기

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

    def solution(my_string, m, c):
        arr = []
    
        prev = 0
        for step in range(0, len(my_string), m):
            if my_string[prev:step]:
                arr.append(my_string[prev:step])
            if step == len(my_string) - m:
                arr.append(my_string[step:len(my_string) + m])
    
            prev = step
    
        answer = ""
        for ar in arr:
            answer += ar[c - 1]
        return answer
    

     

    수열과 구간 쿼리 1

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

    def solution(arr, queries):
    
        for s, e in queries:
            for i in range(s, e+1):
                arr[i] += 1
    
        return arr
    

     

    날짜 비교하기

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

    def solution(date1, date2):
        y1, m1, d1 = date1
        y2, m2, d2 = date2
    
        x = datetime.datetime(y1, m1, d1)
        y = datetime.datetime(y2, m2, d2)
    
        if x  < y:
            return 1
        return 0
    

     

    등차수열의 특정한 항만 더하기

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

    def solution(a, d, included):
        answer = 0
        for idx, value in enumerate(included, start=1):
            if idx <= len(included) and value:        
                answer += a
            a = a + d
        return answer
    

     

    글자 지우기

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

    def solution(my_string, indices):
        answer = ""
        for i,v in enumerate(my_string):
            if i not in indices:
                answer += my_string[i]
        return answer
    
    728x90
    반응형