본문 바로가기
  • think together
카테부 4기 판교 ai 실무/코테 공부

프로그래머스 코딩 기초 트레이닝 Day8

by hwamgai 2026. 5. 23.

문제 : 간단한 논리 연산

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

 

프로그래머스

SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 

 

 

내 코드

def v(x,y) :
    if x is False and y is False :
        return False
    else:
        return True

def a(x,y) :
    if x is True and y is True:
        return True
    else:
        return False

def solution(x1, x2, x3, x4):
    answer = a(v(x1,x2), v(x3,x4))

    return answer

 

좋은 코드

def solution(x1, x2, x3, x4):
    return (x1 | x2) & (x3 | x4)
def solution(x1, x2, x3, x4):
    return (x1 or x2) and (x3 or x4)
def solution(x1, x2, x3, x4):
    answer= (x1 or x2) and (x3 or x4)
    return answer

 

 

 

 

문제 : 간단한 논리 연산

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

 

프로그래머스

SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 

 

내 코드

def solution(a, b, c, d):
    x = set([a,b,c,d])

    if len(x) == 4 :
        return min(x)
    elif len(x) == 3 :
        if a == b :
            return c*d
        elif a == c :
            return b*d
        elif a == d:
            return b*c
        elif b == c:
            return a*d
        elif b == d:
            return a*c
        elif c == d:
            return a*b
    elif len(x) == 2 :
        if a == b and c == d:
            return (a+c)*abs(a-c)
        elif a == c and b == d :
            return (a+b)*abs(a-b)
        elif a == d and b == c:
            return (a+b)*abs(a-b)
        else :
        #제미나이 도움 부분
            i = None
            j = None

            for num in x:
                if [a,b,c,d].count(num) == 3:
                    i = num
                elif [a,b,c,d].count(num) == 1:
                    j = num
            return ((10 * i + j) ** 2)     
    elif len(x) == 1 :
        return 1111*a

 

좋은 코드

def solution(a, b, c, d):
    answer = 0
    if a==b==c==d:
        answer=1111*a
    elif a==b==c:
        answer=(10*a+d)**2
    elif a==b==d:
        answer=(10*a+c)**2
    elif a==c==d: 
        answer=(10*a+b)**2
    elif b==c==d:
        answer=(10*d+a)**2
    elif a==b and c==d:
        answer=(a+c)*abs(a-c)
    elif a==c and b==d:
        answer=(a+b)*abs(a-b)
    elif a==d and b==c:
        answer=(a+b)*abs(a-b)
    elif a==b:
        answer=c*d
    elif a==c:
        answer=b*d
    elif a==d:
        answer=b*c
    elif b==c:
        answer=a*d
    elif b==d:
        answer=a*c
    elif c==d:
        answer=a*b
    else:
        answer=min(a,b,c,d)

    return answer

 

 


5/26 

 

 

문제 : 글자 이어 붙여 문자열 만들기

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

 

프로그래머스

SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 

내 코드

def solution(my_string, index_list):
    answer = ''

    for i in index_list:
        answer += my_string[i]
    return answer

 

좋은 코드

def solution(my_string, index_list):
    return ''.join([my_string[idx] for idx in index_list])

 

 

 

 

문제 : 9로 나눈 나머지

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

 

프로그래머스

SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 

 

내 코드

def solution(number):
    answer = int(number)%9
    return answer
def solution(number):
    a = 0
    for i in number:
        a += int(i)
    answer = a%9
    return answer

 

 

 

 

 

문제 : 문자열 여러 번 뒤집기

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

 

프로그래머스

SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 

 

내 코드

def solution(my_string, queries):
    x = list(my_string)


    for i in range(len(queries)):
        arr = []
        str = ''
        for j in range(queries[i][1], queries[i][0]-1, -1):
            arr += x[j]
        x = x[:queries[i][0]] + arr + x[queries[i][1]+1:]


    answer = ''.join(x)
    return answer

 

좋은 코드

def solution(my_string, queries):
    answer=list(my_string)
    for s,e in queries:
        answer[s:e+1]=answer[s:e+1][::-1]
    return ''.join(answer)
def solution(my_string, queries):
    for (s, e) in queries:
        my_string = my_string[:s] + my_string[s:e+1][::-1] + my_string[e+1:]
    return my_string
def solution(my_string, queries):
    answer = ''


    for x in queries:
        my_string = my_string[:x[0]]+ ''.join(reversed(my_string[x[0]:x[1]+1:])) +my_string[x[1]+1:]

    answer = my_string

    return answer