1일 1PS 27일차!

📚 문제


Lv 1

  • String 으로 들어오는 날짜를 오늘 날짜로부터 몇 일이 지났는 지 계산해서 저장해야한다.
  • Int 값으로 저장된 날짜들을 month * 28 과 비교해 유효 기간이 지났는 지 살핀다.

💡 포인트


  1. re 를 사용하여 날짜 입력을 포맷팅하여 받아낸다.
  2. 모든 날짜들을 today 와 비교해 days 를 계산해 Integer 로 저장한다.
  3. 약관의 유효기간도 month 가 아닌 day 로 계산해 비교한다.

💻 코드


import re

def solution(today, terms, privacies):
    pattern = re.compile(r'(\d{4})\.(\d{2})\.(\d{2})')
    today_day = pattern.findall(today)
    answer = []


    for index, p in enumerate(privacies):
        p_day = pattern.findall(p.split(" ")[0])
        days = ((int(today_day[0][0]) - int(p_day[0][0])) * 12 * 28) + ((int(today_day[0][1]) - int(p_day[0][1])) * 28) + ((int(today_day[0][2]) - int(p_day[0][2]))) + 1
        for term in terms:
            if p.split(" ")[1] == term.split(" ")[0]:
                if days > int(term.split(" ")[1]) * 28:
                    answer.append(index + 1)
                break
    return answer

업데이트:

댓글남기기