반응형
문제
https://school.programmers.co.kr/learn/courses/30/lessons/150370
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
문제 풀이
예상 만기일과 오늘 날짜를 비교하여, 예상 만기일이 오늘 날짜보다 이전인 경우만 표시
날짜는 연, 월, 일을 합쳐 일자로 비교함. 모든 달이 28일이라는 조건이 있어서 편안했다~
코드
def date_diff(date, month, today):
y1, m1, d1 = list(map(int,date.split('.')))
y2, m2, d2 = list(map(int,today.split('.')))
m1 += month
if m1 > 12:
y1 += 1
m1 -= 12
tmp = (y2-y1) * (28*12) + (m2 - m1) * 28 + d2 - d1
return int(tmp >= 0)
def solution(today, terms, privacies):
res = []
term_dict = {}
for term in terms:
t, d = term.split()
term_dict[t] = d
for i in range(len(privacies)):
date, p_type = privacies[i].split()
if date_diff(date, int(term_dict[p_type]), today):
res.append(i+1)
return res
반응형
'알고리즘 > 프로그래머스 문제풀이' 카테고리의 다른 글
[프로그래머스] lv.1 인기있는 아이스크림 sql 풀이 (0) | 2023.10.28 |
---|---|
[프로그래머스] lv.1 크레인 인형 뽑기 게임 풀이 (0) | 2023.10.27 |
[프로그래머스] lv.1 키패드 누르기 풀이 (0) | 2023.10.26 |
[프로그래머스] lv.1 문자열을 정수로 바꾸기 python 풀이 (0) | 2023.10.26 |
[프로그래머스] 둘만의 암호 풀이 (0) | 2023.10.26 |