팡세영
Log sey
팡세영
전체 방문자
오늘
어제
  • 분류 전체보기 (73)
    • PS (45)
      • programmers (13)
      • 백준 (29)
    • Android (16)
    • Daily (0)
    • Kotlin (6)
    • Design Pattern (1)
    • Java (1)
    • Flutter (1)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • 해쉬맵
  • ArcitecturePattern
  • compose
  • mvvm
  • programmers #프로그래머스
  • 프로그래머스
  • 정렬
  • Android
  • 백준
  • DFS
  • CustomView
  • TestCode
  • 골드
  • 코틀린
  • 문자열
  • programmers
  • 구현
  • binding
  • 실버
  • 완전탐색
  • Kotlin
  • flutter
  • 이분탐색
  • LEVEL2
  • java
  • BFS
  • 의존성 주입
  • 안드로이드
  • 자바
  • 하단네비게이션바

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
팡세영

Log sey

프로그래머스 - 개인정보 수집 유효기간
PS/programmers

프로그래머스 - 개인정보 수집 유효기간

2023. 1. 18. 23:15


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

 

프로그래머스

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

programmers.co.kr


[문제 풀이]

  • 해당 문제는 간단한 구현 문제인 것 같습니다.
  • (개인정보 수집 일자 + 유효기간) -1  < 현재 날짜이면 배열에 추가 
  • 날짜를 split 함수로 연, 월, 일을 구별해준 뒤 연도에는 336일을 곱해주고 월에는 28일을 곱해줬습니다.
  • 만기일 계산하기 위해 약관 종류를 해쉬맵에 담아 불러왔습니다.

[Java]

 

import java.io.*;
import java.util.*;


class Solution {
    public Object[] solution(String today, String[] terms, String[] privacies) {
        ArrayList<Integer> list = new ArrayList<>();

        String [] todayToken = today.split("\\.");

        // curDay = today
        int curDay = parseYear(todayToken[0]) + parseMonth(todayToken[1]) + parseDay(todayToken[2]);
        HashMap<String, Integer> term = new HashMap<>();

        // init terms
        for(int i=0; i<terms.length; i++){
            String tmp[] = terms[i].split(" ");
            term.put(tmp[0], Integer.parseInt(tmp[1]));
        }

        for(int i=0; i<privacies.length; i++){
            String tokenDate[] = privacies[i].split("\\.| ");
            int targetDay = parseYear(tokenDate[0]) + parseMonth(tokenDate[1])+ parseDay(tokenDate[2]);
            int dueDay = targetDay + (term.get(tokenDate[3]) * 28)-1; // expireDate

            if(curDay > dueDay) list.add(i+1);
        }

        return list.toArray(new Integer[0]);
    }

    public int parseYear(String year){
        return Integer.parseInt(year) * 336;
    }

    public int parseMonth(String month){
        return Integer.parseInt(month) * 28;
    }

    public int parseDay(String day){
        return Integer.parseInt(day);
    }
}


public class Main {


    public static void main(String args[]) throws IOException {

//        new Solution().solution("2022.05.19", new String[]{"A 6", "B 12", "C 3"},
//                new String[]{"2021.05.02 A", "2021.07.01 B", "2022.02.19 C", "2022.02.20 C"});

        new Solution().solution("2020.01.01", new String[]{"Z 3", "D 5"},
                new String[]{"2019.01.01 D", "2019.11.15 Z", "2019.08.02 D", "2019.07.01 D", "2018.12.28 Z"});



    }




}

'PS > programmers' 카테고리의 다른 글

[프로그래머스] - 소수찾기  (0) 2023.02.10
[프로그래머스] - 무인도 여행  (0) 2023.01.27
프로그래머스 - 프렌즈 4블록  (0) 2022.08.30
Programmers - 피로도 (Java) 완전탐색  (0) 2022.08.10
[프로그래머스] 기능개발  (1) 2022.06.27
    'PS/programmers' 카테고리의 다른 글
    • [프로그래머스] - 소수찾기
    • [프로그래머스] - 무인도 여행
    • 프로그래머스 - 프렌즈 4블록
    • Programmers - 피로도 (Java) 완전탐색
    팡세영
    팡세영
    Android, CS, PS

    티스토리툴바