개인정보 수집 유효기간 (문자열, 구현)

2023. 6. 26. 10:47·Coding Test/programmers
728x90
"""
오늘 날짜를 의미하는 문자열 today,
약관의 유효기간을 담은 1차원 문자열 배열 terms 1 ≤ terms의 길이 ≤ 20
수집된 개인정보의 정보를 담은 1차원 문자열 배열 privacies 1 ≤ privacies의 길이 ≤ 100
파기해야 할 개인정보의 번호를 오름차순으로 1차원 정수 배열에 담아 return
"""
def solution(today, terms, privacies):
    answer = []

    #오늘 날짜
    nyear = int(today[:4])
    nmonth = int(today[5:7])
    nday = int(today[8:])

    for i in range(len(terms)):
        for j in range(len(privacies)):

            if terms[i][0] == privacies[j][-1]:  # 약관종류

                # 개인정보 수집일자
                year = int(privacies[j][:4])
                month = int(privacies[j][5:7]) + int(terms[i][2:])
                day = int(privacies[j][8:10]) - 1

                # print(privacies[j], year, month, day)

                while month > 12:
                    month -= 12
                    year += 1

                if day <= 0:
                    day = 28
                    month -= 1
                    if month <= 0:
                        month = 12
                        year -= 1

                if nyear > year:
                    answer.append(j + 1)
                elif nyear == year:
                    if nmonth > month:
                        answer.append(j + 1)
                    elif nmonth == month:
                        if nday > day:
                            answer.append(j + 1)
    answer.sort()
    return answer

print(solution("2022.05.19", ["A 6", "B 12", "C 3"], ["2021.05.02 A", "2021.07.01 B", "2022.02.19 C", "2022.02.20 C"]))

 

 

 

728x90
저작자표시 비영리 변경금지
'Coding Test/programmers' 카테고리의 다른 글
  • K진수에서 소수의 개수 구하기
  • 표병합 (구현, 유니온파인드)
  • 택배 배달과 수거하기 (그리디)
  • 이모티콘 할인행사 (완전 탐색, 조합)
Karla Ko
Karla Ko
𝘾𝙤𝙣𝙩𝙞𝙣𝙪𝙤𝙪𝙨𝙡𝙮 𝙄𝙢𝙥𝙧𝙤𝙫𝙞𝙣𝙜, 𝘾𝙤𝙣𝙨𝙩𝙖𝙣𝙩𝙡𝙮 𝘿𝙚𝙫𝙚𝙡𝙤𝙥𝙞𝙣𝙜 𝙔𝙚𝙨!
    250x250
  • Karla Ko
    karlaLog
    Karla Ko
  • 전체
    오늘
    어제
    • Total (467)
      • Spring (19)
      • JPA (4)
      • Cloud & Architecture (15)
        • Kubernetes (5)
        • Docker (3)
        • MSA (2)
        • GCP (1)
        • AWS (4)
      • Devops (1)
      • Message Queue (4)
        • Kafka (2)
        • RabbitMQ (2)
      • Git (4)
      • DB (4)
      • Java (9)
      • Python (4)
      • CS (11)
        • OS (8)
        • Network (2)
        • Algorithm (1)
      • Coding Test (392)
        • programmers (156)
        • Graph (43)
        • DP (37)
        • Search (31)
        • Tree (13)
        • Data Structure (26)
        • Combination (12)
        • Implement (18)
        • Geedy (23)
        • Sort (7)
        • Math (21)
        • geometry (2)
  • 블로그 메뉴

    • 홈
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    프로그래머스
    힙
    최소신장트리
    이분탐색
    자료구조
    BFS
    최단거리
    구현
    알고리즘
    조합
    플로이드워셜
    다익스트라
    백준
    스택
    파이썬
    LIS
    월간코드챌린지
    정렬
    Algorithm
    DP
    DFS
    구간합
    최대공약수
    그리디
    재귀
    그래프
    큐
    동적계획법
    트리
    덱
  • hELLO· Designed By정상우.v4.10.3
Karla Ko
개인정보 수집 유효기간 (문자열, 구현)
상단으로

티스토리툴바