삽집하는 개발들/알고리즘

[9일차][프로그래머스][2023 카카오 - 150370]개인정보 수집 유효성 검사

악투 2023. 6. 19. 15:25
반응형
def timestamp_create(year, month, day):
    timestamp_today = (int(year) * 12 * 28) + (int(month) * 28) + (int(day))    
    return timestamp_today
        
def solution(today, terms, privacies):
    # timestamp로 비교
    year, month, day = today.split('.')
    timestamp_today = timestamp_create(year, month, day)
    terms_obj = { data.split(' ')[0] : data.split(' ')[1]  for data in terms }
    answer = []
    
    
    for idx, data in enumerate(privacies):
        p_date, p_type = data.split(' ')        
        p_year, p_month, p_day = p_date.split('.')
        timestamp_p = timestamp_create(p_year, p_month, p_day) + (int(terms_obj[p_type]) * 28)
        
        if int(timestamp_p) <= int(timestamp_today):
            answer.append(idx+1)
    
    return answer
def solution(today, terms, privacies):
    answer = []
    for data in terms:
        type, month = data.split(' ')
        for idx, val in enumerate(privacies):
            date, term_type = val.split(' ')
            if term_type == type:
                now_year, now_month, now_day = today.split('.')
                terms_year, terms_month, terms_day = date.split('.')
                
                if int(terms_month) + int(month) > 12:
                    year_remainder = (int(terms_month) + int(month)) % 12  
                    if year_remainder == 0:                        
                        add_year = ((int(terms_month) + int(month)) // 12) - 1
                        add_month = 12
                    else:
                        add_year = ((int(terms_month) + int(month)) // 12)                        
                        add_month = (int(terms_month) + int(month)) % 12   
                        
                    terms_year = int(terms_year) + int(add_year)
                    
                    if int(terms_month) == 1 and int(terms_day) == 1:
                        terms_year = int(terms_year) - 1
                        terms_month = 12
                        terms_day = 28
                    else:
                        if int(terms_day) == 1:                    
                            terms_month = add_month - 1
                            terms_day = 28
                        else:
                            terms_month = add_month
                            terms_day = int(terms_day) - 1  
                else:
                    terms_month = int(terms_month) + int(month)
                    
                    if int(terms_month) == 1 and int(terms_day) == 1:                     
                        terms_year = int(terms_year) - 1
                        terms_month = 12
                        terms_day = 28
                    else:                    
                        if int(terms_day) == 1:                        
                            terms_month = terms_month - 1
                            terms_day = 28
                        else:
                            terms_day = int(terms_day) - 1

                if int(terms_year) < int(now_year):
                    answer.append(idx+1)
                elif int(terms_year) == int(now_year):
                    if int(terms_month) < int(now_month):
                        answer.append(idx+1)
                    elif int(terms_month) == int(now_month):
                        if int(terms_day) < int(now_day):
                            answer.append(idx+1)
                        elif int(terms_day) == int(now_day):                            
                            pass
                        else:
                            pass
                    else:
                        pass
                else:
                    pass   
    
    answer.sort()
    
    return answer
반응형