함께하는 데이터 분석

[Programmers] 프로그래머스 파이썬 lv1 본문

코딩 테스트/프로그래머스

[Programmers] 프로그래머스 파이썬 lv1

JEONGHEON 2023. 7. 12. 19:52

나머지가 1이 되는 수 찾기

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

 

평균 구하기

def solution(arr):
    answer = sum(arr)/len(arr)
    return answer
def solution(arr) :
    return sum(arr) / len(arr)

 

짝수와 홀수

def solution(num):
    if num % 2 == 0 :
        return "Even"
    else :
        return "Odd"
def solution(num) :
    return 'Even' if num % 2 == 0 else 'Odd'

 

약수의 합

def solution(n):
    summ = 0
    for i in range(1, n + 1) :
        if n % i == 0 :
            summ += i
    return summ
def solution(n) :
    return sum([i for i in range(1, n + 1) if n % i == 0])

 

자릿수 더하기

def solution(n):
    n = list(str(n))
    summ = 0
    for i in n :
        summ += int(i)
    return summ
def solution(n) :
    return sum([int(i) for i in str(n)])

 

x만큼 간격이 있는 n개의 숫자

def solution(x, n):
    a = x
    answer = []
    for i in range(n) :
        answer.append(x)
        x += a
    return answer
def solution(x, n) :
    return [x * i for i in range(1, n + 1)]

 

문자열 내 p와 y의 개수

def solution(s):
    a = 0
    b = 0
    for i in s:
        if i == "p" or i== "P":
            a += 1
        elif i == "y" or i == "Y":
            b += 1
    return a == b
def solution(s) :
    return s.lower().count('p') == s.lower().count('y')

 

자연수 뒤집어 배열로 만들기

def solution(n):
    n = str(n)
    a = len(n)
    answer = []
    for i in range(a - 1, -1, -1) :
        answer.append(int(n[i]))
    return answer
def solution(n) :
    arr = [int(i) for i in str(n)]
    arr.reverse()
    return arr

 

정수 제곱근 판별

def solution(n):
    sqrt = n ** (1 / 2)
    if sqrt % 1 == 0 :
        return (sqrt + 1) ** 2
    else :
        return -1
import math
def solution(n) :
    return int((math.sqrt(n) + 1) ** 2) if math.sqrt(n) % 1 == 0 else -1

 

문자열을 정수로 바꾸기

def solution(s):
    return int(s)

 

정수 내림차순으로 배치하기

def solution(n):
    answer = list(str(n))
    answer.sort(reverse = True)
    return int(''.join(answer))

 

하샤드 수

def solution(x):
    x = str(x)
    summ = 0
    for i in x :
        summ += int(i)
    x = int(x)
    if x % summ == 0 :
        return True
    else :
        return False

 

두 정수 사이의 합

def solution(a, b):
    summ = 0
    if a <= b :
        for i in range(a, b + 1) :
            summ += i
    else :
        for i in range(b, a + 1) :
            summ += i
    return summ

 

콜라츠 추측

def solution(num):
    a = 0
    while num > 1 :
        if num % 2 == 0 :
            num /= 2
        else :
            num = 3 * num + 1
        a += 1
    if a <= 500 :
        return a
    else :
        return -1

 

나누어 떨어지는 숫자 배열

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

 

서울에서 김서방 찾기

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

 

음양 더하기

def solution(absolutes, signs):
    answer = []
    for i in range(len(absolutes)) :
        if signs[i] == True :
            answer.append(absolutes[i])
        else :
            answer.append(-absolutes[i])
    return sum(answer)

 

핸드폰 번호 가리기

def solution(phone_number):
    answer = []
    for i in range(len(phone_number) - 4) :
        answer.append('*')
    for i in range(-4, 0, 1) :
        answer.append(phone_number[i])
    return ''.join(answer)

 

없는 숫자 더하기

def solution(numbers):
    answer = []
    for i in range(1, 10) :
        if i not in numbers :
            answer.append(i)
    return sum(answer)

 

제일 작은 수 제거하기

def solution(arr):
    if len(arr) == 1 :
        return [-1]
    else :
        arr.remove(min(arr))
        return arr

 

가운데 글자 가져오기

def solution(s):
    if len(s) % 2 == 0 :
        return f'{s[int(len(s) / 2) - 1]}{s[int(len(s) / 2)]}'
    else :
        return s[int(len(s) / 2)]

 

수박수박수박수박수박수

def solution(n):
    answer = []
    for i in range(n) :
        if i % 2 == 0 :
            answer.append('수')
        else :
            answer.append('박')        
    return ''.join(answer)

 

내적

def solution(a, b):
    answer = []
    for i in range(len(a)) :
        answer.append(a[i] * b[i])
    return sum(answer)

 

약수의 개수와 덧셈

def solution(left, right):
    answer = []
    for i in range(left, right + 1) :
        count = 0
        for j in range(1, i + 1) :
            if i % j == 0 :
                count += 1        
        if count % 2 == 0 :
            answer.append(i)
        else :
            answer.append(-i)
    return sum(answer)

 

문자열 내림차순으로 배치하기

def solution(s):
    return ''.join(reversed(sorted(s)))

 

부족한 금액 계산하기

def solution(price, money, count):
    answer = 0
    a = 0
    for i in range(count) :
        answer += price
        a += answer
    if a - money >= 0 :
        return a - money
    else :
        return 0

 

문자열 다루기 기본

def solution(s):
    if s.isnumeric() and (len(s) == 4 or len(s) == 6) :
        return True
    else :
        return False

 

행렬의 덧셈

def solution(arr1, arr2):
    a = []
    for i in range(len(arr1)) :
        b = []
        for j in range(len(arr1[i])) :
            b.append(arr1[i][j] + arr2[i][j])
        a.append(b)
    return a

 

직사각형 별찍기

a, b = map(int, input().split())
print(('*' * a + '\n') * b)

 

최대공약수와 최소공배수

def solution(n, m):
    for i in range(min(n, m), 0, -1):
        if n % i == 0 and m % i == 0:
            break
    for j in range(max(n, m), n * m + 1):
        if j % n == 0 and j % m == 0:
            break
    return [i, j]
import math
def solution(n, m) :
    return [math.gcd(n, m), math.lcm(n, m)]

 

같은 숫자는 싫어

def solution(s) :
    arr = []
    for i in s :
        if arr[-1:] == [i] : 
            continue
        arr.append(i)
    return arr

 

3진법 뒤집기

def solution(n) :
    
    def rev(n, q):
        rev_base = ''

        while n > 0:
            n, mod = divmod(n, q)
            rev_base += str(mod)

        return rev_base[::-1]

    answer = rev(n, 3)

    arr = []
    for i in range(len(answer) - 1, -1, -1) :
        arr.append(answer[i])
    
    result = ''.join(arr)
    
    return int(result, 3)

 

이상한 문자 만들기

def solution(s) :
    data = list(map(str, s.split(' ')))

    arr = []
    for i in data :
        arr1 = []
        for j in i :
            arr1.append(j)
        arr.append(arr1)

    answer = []
    for i in arr :
        for j in range(len(i)) :
            if j % 2 == 0 :
                i[j] = i[j].upper()
            else :
                i[j] = i[j].lower()
        answer.append(''.join(i))

    return ' '.join(answer)

 

예산

def solution(d, budget) :
    summ = 0
    count = 0

    d.sort()

    for i in d :
        summ += i
        if summ > budget :
            break
        count += 1
    return count

 

삼총사

from itertools import combinations

def solution(number) :
    result = list(combinations(number, 3))

    arr = []
    for i in range(len(result)) :
        arr.append(sum(result[i]))

    count = 0
    for j in range(len(arr)) :
        if arr[j] == 0 :
            count += 1
    return count

 

시저 암호

def solution(s, n) :
    alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
    ALPHA = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
    answer = ''

    for i in range(len(s)) :
        if s[i] == ' ' :
            answer += ' '
        else :
            for j in range(len(alpha)) :
                if s[i] == alpha[j] :
                    answer += alpha[(j + n) % len(alpha)]
                elif s[i] == ALPHA[j] :
                    answer += ALPHA[(j + n) % len(ALPHA)]

    return answer

 

최소 직사각형

def solution(sizes) :
    for i in range(len(sizes)) :
        if sizes[i][0] < sizes[i][1] :
            sizes[i][0], sizes[i][1] = sizes[i][1], sizes[i][0]

    arr1 = []
    for i in range(len(sizes)) :
        arr1.append(sizes[i][0])
    arr1.sort(reverse = True)
    
    arr2 = []
    for i in range(len(sizes)) :
        arr2.append(sizes[i][1])
    arr2.sort(reverse = True)

    return arr1[0] * arr2[0]

 

크기가 작은 부분 문자열

def solution(t, p) :
    lent = len(t)
    lenp = len(p)

    arr = []

    for i in range(lent - lenp + 1) :
        arr.append(int(t[i:lenp + i]))

    count = 0
    for i in arr :
        if i <= int(p) :
            count += 1
    return count

 

[1차] 비밀지도

def solution(n, arr1, arr2) :
    arr1_2 = []
    for i in arr1 :
        arr1_2.append(bin(i)[2:])

    arr2_2 = []
    for i in arr2 :
        arr2_2.append(bin(i)[2:])

    for i in range(len(arr1_2)) :
        arr1_2[i] = '0' * (n - len(arr1_2[i])) + arr1_2[i]

    for i in range(len(arr2_2)) :
        arr2_2[i] = '0' * (n - len(arr2_2[i])) + arr2_2[i]

    result = []
    for i in range(len(arr1_2)) :
        answer = []
        for j in range(n) :
            if arr1_2[i][j] == '1' or arr2_2[i][j] == '1' :
                a = '#'
            else :
                a = ' '
            answer.append(a)
        result.append(answer)

    answer = []
    for i in range(len(result)) :
        answer.append(''.join(result[i]))

    return answer

 

숫자 문자열과 영단어

def solution(s) :
    dic = {'zero' : '0',
           'one' : '1',
           'two' : '2',
           'three' : '3',
           'four' : '4',
           'five' : '5',
           'six' : '6',
           'seven' : '7',
           'eight' : '8',
           'nine' : '9'}

    for key, value in dic.items() :
        s = s.replace(key, value)
    return s

 

문자열 내 마음대로 정렬하기

def solution(strings, n) :
    arr = []
    for i in strings :
        arr.append((i, i[n]))

    arr = sorted(arr, key = lambda x : (x[1], x))

    arr1 = []
    for j in arr :
        arr1.append(j[0])

    return arr1

 

k번째수

def solution(array, commands) :
    arr = []
    for i in range(len(commands)) :
        arr1 = []
        for j in range(commands[i][0] - 1, commands[i][1]) :
            arr1.append(array[j])
            arr1.sort()
        arr.append(arr1)
    arr2 = []
    for i in range(len(commands)) :
        arr2.append(arr[i][commands[i][2] - 1])
        
    return arr2

 

두 개 뽑아서 더하기

from itertools import combinations

def solution(numbers) :
    result = list(combinations(numbers, 2))

    arr = []
    for i in range(len(result)) :
        arr.append(sum(result[i]))
        
    return sorted(list(set(arr)))

 

푸드 파이트 대회

def solution(food) :
    food.pop(0)

    result = ''
    for i in range(1, len(food) + 1) :
        a = food[i - 1] // 2
        result += str(i) * a

    return result + '0' + result[::-1]

 

가장 가까운 글자

def solution(s) :
    result = []
    for i in range(len(s)) :
        if s[i] in s[:i] :
            arr = []
            for j in range(len(s[:i])) :
                if s[i] == s[j] :
                    arr.append(j)
            result.append(i - arr[-1])
        else :
            result.append(-1)
                
    return result

 

콜라 문제

def solution(a, b, n) :
    summ = 0
    while n >= a :
        bottle = n // a * b
        n = n - (n // a) * a + bottle
        summ += bottle
    
    return summ

 

추억점수

def solution(names, yearing, photo) :
    answer = []
    for i in photo :
        score = 0
        for j in range(len(names)) :
            if names[j] in i :
                score += yearing[j]
        answer.append(score)
    return answer

 

2016년

def solution(a, b) :
    month = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
    day = ['THU', 'FRI', 'SAT', 'SUN', 'MON', 'TUE', 'WED']

    answer = day[(sum(month[:a - 1]) + b) % len(day)]
    return answer

 

명예의 전당 (1)

def solution(k, score) :
    answer = []
    for i in range(1, len(score) + 1) :
        if i >= k + 1 :
            answer.append(sorted(score[:i])[i - k])
        else :
            answer.append(sorted(score[:i])[0])

    return answer

 

폰켓몬

def solution(nums) :
    return min(len(nums) // 2, len(set(nums)))

 

과일 장수

def solution(k, m, score) :
    score.sort(reverse = True)

    length = len(score)

    arr = []
    for i in range(1, length + 1) :
        if i % m == 0 :
            arr.append(score[i - 1])

    summ = 0
    for i in arr :
        summ += i

    return summ * m

 

카드 뭉치

def solution(cards1, cards2, goal) :
    arr = []
    for i in range(len(goal)) :
        arr.append((goal[i], i))
    
    for i in range(len(cards1)) :
        if cards1[i] not in goal :
            cards1[i] = len(goal)
        
    for i in range(len(cards2)) :
        if cards2[i] not in goal :
            cards2[i] = len(goal)

    for i in range(len(cards1)) :
        for j in range(len(arr)) :
            if cards1[i] == arr[j][0] :
                cards1[i] = arr[j][1]

    for i in range(len(cards2)) :
        for j in range(len(arr)) :
            if cards2[i] == arr[j][0] :
                cards2[i] = arr[j][1]

    return 'Yes' if sorted(cards1) == cards1 and sorted(cards2) == cards2 else 'No'

 

모의고사

def solution(answers) :
    arr1 = [1, 2, 3, 4, 5]
    arr2 = [2, 1, 2, 3, 2, 4, 2, 5]
    arr3 = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]
    count = [0] * 3

    for i in range(len(answers)):
        if answers[i] == arr1[i%len(arr1)]:
            count[0] += 1
        if answers[i] == arr2[i%len(arr2)]:
            count[1] += 1
        if answers[i] == arr3[i%len(arr3)]:
            count[2] += 1

    arr = []
    for j in range(len(count)) :
        if count[j] == max(count) :
            arr.append(j + 1)
    return arr

 

소수 만들기

import math
from itertools import combinations

def solution(nums) :
    result = list(combinations(nums, 3))
    
    arr = []
    for i in range(len(result)) :
        arr.append(sum(result[i]))
    arr.sort()

    array = [True for i in range(100001)]
    array[1] = 0

    for i in range(2, int(math.sqrt(arr[-1])) + 1) :
        if array[i] == True :
            j = 2
            while i * j <= arr[-1] :
                array[i * j] = False
                j += 1

    count = 0
    for i in arr :
        if array[i] == True :
            count += 1
    return count

 

소수찾기

import math

def solution(n) :
    array = [True for i in range(1000001)]
    array[1] = 0

    for i in range(2, int(math.sqrt(n)) + 1) :
        if array[i] == True :
            j = 2
            while i * j <= n :
                array[i * j] = False
                j += 1

    count = 0
    for i in range(2, n + 1) :
        if array[i] == True :
            count += 1
    return count

 

실패율

def solution(N, stages) :
    length = len(stages)

    array = []
    for i in range(1, N + 1) :
        count = stages.count(i)
    
        if length == 0 :
            fail = 0
        else :
            fail = count / length
    
        length -= count
        array.append((fail, i))
    
    array.sort(key = lambda x : (-x[0], x[1]))

    answer = []
    for i in array :
        answer.append(i[1])
    
    return answer

 

덧칠하기

from collections import deque

def solution(n, m, section) :
    section = deque(section)
    count = 0
    while True :
        num = section.popleft()
        for _ in range(m) :
            if len(section) != 0 :
                if section[0] < num + m :
                    section.popleft()
                else :
                    break
            else :
                break
    
        count += 1
        if len(section) == 0 :
            break

    return count

 

기사단원의 무기

import math

def solution(number, limit, power) :
    num = [1]
    for i in range(2, number + 1) :
        count = 0
        for j in range(1, int(math.sqrt(i)) + 1) :
            if j * j == i :
                count += 1
            elif i % j == 0 :
                count += 2
        num.append(count)

    summ = 0
    for i in num :
        if i > limit :
            summ += power
        else :
            summ += i
    
    return summ

 

[1차] 다트 게임

def solution(dartResult) :
    answer = []
    for i in dartResult :
        if not i.isnumeric() : 
            idx = dartResult.index(i)
            if i == 'S' :
                answer.append(int(dartResult[:idx]) ** 1)
            elif i == 'D' :
                answer.append(int(dartResult[:idx]) ** 2)
            elif i == 'T' :
                answer.append(int(dartResult[:idx]) ** 3)
            elif i == '#' :
                answer[-1] *= -1
            elif i == '*' :
                answer[-1] *= 2
                if len(answer) >= 2 :
                    answer[-2] *= 2
            
            dartResult = dartResult[idx + 1:]
        
    return sum(answer)

 

로또의 최고 순위와 최저 순위

def solution(lottos, win_nums) :
    count = 0
    for i in lottos :
        if i in win_nums :
            count += 1

    count_0 = lottos.count(0)

    minn = count
    maxx = count + count_0

    rank = [6, 6, 5, 4, 3, 2, 1]
    
    return rank[maxx], rank[minn]

 

숫자 짝꿍

def solution(X, Y):
    answer = ''

    for i in range(9, -1, -1) :
        answer += (str(i) * min(X.count(str(i)), Y.count(str(i))))

    if answer == '' :
        return '-1'
    elif len(answer) == answer.count('0'):
        return '0'
    else :
        return answer

 

옹알이 (2)

def solution(babbling) :
    arr = ["aya", "ye", "woo", "ma"]

    count = 0
    for i in babbling :
        for j in arr :
            if j * 2 not in i :
                i = i.replace(j, ' ')
        if len(i.strip()) == 0 :
            count += 1
        
    return count

 

체육복

def solution(n, lost, reserve):
    count = 0
    for i in range(1, n + 1):
        if i not in lost:
            count += 1
        else:
            if i in reserve:
                count += 1
                reserve.remove(i)
                lost.remove(i)

    for i in lost:
        if i - 1 in reserve:
            count += 1
            reserve.remove(i - 1)

        elif i + 1 in reserve:
            count += 1
            reserve.remove(i + 1)

    return count

 

완주하지 못한 선수

def solution(participant, completion) :
    from collections import Counter

    p = dict(Counter(participant))
    c = dict(Counter(completion))

    for i in p :
        if i not in c or p[i] > c[i] :
            return i

 

문자열 나누기

def solution(s):
    answer = 0
    count1 = 0
    count2 = 0
    
    for i in s:
        if count1 == count2 :
            answer += 1
            alpha = i
        if i == alpha :
            count1 += 1
        else:
            count2 += 1
    
    return answer

 

대충 만든 자판

def solution(keymap, targets) :
    dic = {}

    for i in keymap :
        for j in i :
            if j not in dic :
                dic[j] = i.index(j) + 1
            else :
                dic[j] = min(dic[j], i.index(j) + 1)

    answer = []
    for i in targets :
        count = 0
        for j in i :
            if j in dic :
                count += dic[j]
            else :
                count = -1
                break
        answer.append(count)
    
    return answer

 

둘만의 암호

def solution(s, skip, index) :
    alpha = 'abcdefghijklmnopqrstuvwxyz'

    answer = ''
    for i in alpha :
        if i not in skip :
            answer += i

    result = ''
    for i in s :
        result += answer[(answer.index(i) + index) % len(answer)]
        
    return result

 

크레인 인형뽑기 게임

def solution(board, moves) :
    arr = []
    for i in range(len(board)) :
        arr1 = []
        for j in range(len(board[i])) :
            if board[j][i] != 0 :
                arr1.append(board[j][i])          
        arr.append(arr1)

    count = 0
    answer = []
    for i in moves :
        if len(arr[i - 1]) != 0 :
            result = arr[i - 1].pop(0)
            if len(answer) == 0 :
                answer.append(result)
            else :
                if answer[-1] == result :
                    count += 2
                    answer.pop()
                else :
                    answer.append(result)
            
    return count

 

키패드 누르기

def solution(numbers, hand) :
    answer = ''
    leftloc, rightloc = 10, 12 

    for i in numbers :
        if i in [1, 4, 7] :
            leftloc = i
            answer += 'L'
        elif i in [3, 6, 9] :
            rightloc = i
            answer += 'R'
        else :
            if i == 0 :
                i = 11
            lloc = abs(i - leftloc)
            rloc = abs(i - rightloc)
        
            if sum(divmod(lloc, 3)) > sum(divmod(rloc, 3)) :
                rightloc = i
                answer += 'R'
            elif sum(divmod(lloc, 3)) < sum(divmod(rloc, 3)) :
                leftloc = i
                answer += 'L'
            else :
                if hand == 'left' :
                    leftloc = i
                    answer += 'L'
                else :
                    rightloc = i
                    answer += 'R'
        
    return answer

 

신규 아이디 추천

def solution(new_id) :
    # 1단계
    new_id = new_id.lower()

    # 2단계
    new_id1 = ''
    for i in new_id :
        if i in ['-', '_', '.'] or i.isalpha() or i.isnumeric() :
            new_id1 += i

    # 3단계
    new_id2 = ''
    for i in new_id1 :
        if len(new_id2) == 0 :
            new_id2 += i
        else :
            if new_id2[-1] == '.' and i == '.' :
                continue
            else :
                new_id2 += i

    # 4단계
    if len(new_id2) >= 1 :
        if new_id2[0] == '.' :
            new_id2 = new_id2[1:]
    if len(new_id2) >= 1 :    
        if new_id2[-1] == '.' :
            new_id2 = new_id2[:-1]

    # 5단계
    if len(new_id2) == 0 :
        new_id2 = 'a'

    # 6단계
    if len(new_id2) >= 16 :
        new_id2 = new_id2[:15]

    if new_id2[-1] == '.' :
        new_id2 = new_id2[:-1]
    
    # 7단계
    if len(new_id2) == 1 :
        new_id2 += new_id2[-1] * 2
    elif len(new_id2) == 2 :
        new_id2 += new_id2[-1]
            
    return new_id2

 

햄버거 만들기

def solution(ingredient) :
    count = 0
    arr = []

    for i in ingredient :
        arr.append(i)
        if arr[-4:] == [1, 2, 3, 1] :
            count += 1
            for _ in range(4) :
                arr.pop()
            
    return count

 

성격 유형 검사하기

def solution(survey, choices) :
    score = [['R', 0], ['T', 0], ['C', 0], ['F', 0], ['J', 0], ['M', 0], ['A', 0], ['N', 0]]

    arr = []
    for i in range(len(survey)) :
        arr.append([survey[i], choices[i]])

    for i in range(len(arr)) :
        if arr[i][1] == 1 :
            for j in range(len(score)) :
                if arr[i][0][0] in score[j][0] :
                    score[j][1] += 3
        elif arr[i][1] == 2 :
            for j in range(len(score)) :
                if arr[i][0][0] in score[j][0] :
                    score[j][1] += 2
        elif arr[i][1] == 3 :
            for j in range(len(score)) :
                if arr[i][0][0] in score[j][0] :
                    score[j][1] += 1
        elif arr[i][1] == 5 :
            for j in range(len(score)) :
                if arr[i][0][1] in score[j][0] :
                    score[j][1] += 1
        elif arr[i][1] == 6 :
            for j in range(len(score)) :
                if arr[i][0][1] in score[j][0] :
                    score[j][1] += 2
        elif arr[i][1] == 7 :
            for j in range(len(score)) :
                if arr[i][0][1] in score[j][0] :
                    score[j][1] += 3

    dic = dict(score)

    answer = ''
    if dic['R'] >= dic['T'] :
        answer += 'R'
    else :
        answer += 'T'    
        
    if dic['C'] >= dic['F'] :
        answer += 'C'
    else :
        answer += 'F' 
        
    if dic['J'] >= dic['M'] :
        answer += 'J'
    else :
        answer += 'M'
    
    if dic['A'] >= dic['N'] :
        answer += 'A'
    else :
        answer += 'N'
    
    return answer

 

바탕화면 정리

def solution(wallpaper) :
    arr = []
    for i in range(len(wallpaper)) :
        arr.append([wallpaper[i], i])

    array = []
    for i in arr :
        for j in range(len(i[0])) :
            if i[0][j] in '#' :
                array.append([i[1], j])

    minn = []
    for i in array :
        minn.append(i[0])
    
    minn.sort()

    maxx = []
    for i in array :
        maxx.append(i[1])
    
    maxx.sort()

    lux, luy, rdx, rdy = minn[0], maxx[0], minn[-1] + 1, maxx[-1] + 1
    
    return [lux, luy, rdx, rdy]

 

개인정보 수집 유효기간

def solution(today, terms, privacies) :
    term = []
    for i in terms :
        term.append(i.split(' '))
        
    arr = []
    for i in privacies :
        for j in term :
            if i[-1] in j[0] :
                arr.append([i[:10], j[1]])

    array = []
    for i in arr :
        y, m, d = map(int, i[0].split('.'))
        a = int(i[1])    
        m += a
        
        if d == 1 :
            d = 28
            m -= 1
        else :
            d -= 1
            
        if m > 12 :
            y += (m - 1) // 12 
            m = (m - 1) % 12 + 1
        
        y, m, d = str(y), str(m), str(d)
        
        if len(m) == 1 :
            m = '0' + m
            
        if len(d) == 1 :
            d = '0' + d
        array.append(y + m + d)

    answer = []
    for i in range(len(array)) :
        if int(array[i]) < int(today.replace('.', '')) :
            answer.append(i + 1)
        
    return answer

 

달리기 경주

 

 

공원 산책

 

 

신고 결과 받기

def solution(id_list, report, k) :
    cnt = {} # 유저가 신고당한 횟수
    res = {} # 유저가 신고한 ID

    for i in id_list :
        cnt[i] = 0

    for i in id_list :
        res[i] = []

    for i in set(report) :
        a, b = i.split(' ')
        if b in cnt :
            cnt[b] += 1
        if a in res :
            res[a].append(b)

    answer = []
    for l in res.values() :
        count = 0
        for i, j in cnt.items() :
            if j >= k :
                if i in l :
                    count += 1
        answer.append(count)

    return answer