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

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

현재 날짜 today 유효기간이 적힌 계약 조건, 계약리스트가 주어진다.

유효기간이 지난 리스트번호를 출력한다.

유효기간의 시작은 오늘부터이므로 -1을 해줘야 한다.

def solution(today, terms, privacies):
    answer = []
    date = today.split('.')
    todays = int(date[0])*28*12 + int(date[1])*28 + int(date[2])
    termdic ={}
    for v in terms:
        term = v.split()
        termdic[term[0]] = int(term[1])
    for i,lst in enumerate( privacies):
        temp = lst.split()
        date = temp[0].split('.')
        outdays = int(date[0])*28*12 + int(date[1])*28 + int(date[2])
        outdays += termdic[temp[1]]*28-1
        if outdays < todays:
            answer.append(i+1)
    return answer
    
a="2022.05.19"	
b=["A 6", "B 12", "C 3"]	
c=["2021.05.02 A", "2021.07.01 B", "2022.02.19 C", "2022.02.20 C"]
solution(a,b,c)

다른분은 map()을 이용해 리스트 요소에 int()를 처리해주었고 

def to_days(date):
    year, month, day = map(int, date.split("."))
    return year * 28 * 12 + month * 28 + day

def solution(today, terms, privacies):
    months = {v[0]: int(v[2:]) * 28 for v in terms}
    today = to_days(today)
    expire = [
        i + 1 for i, privacy in enumerate(privacies)
        if to_days(privacy[:-2]) + months[privacy[-1]] <= today
    ]
    return expire

+ Recent posts