개인정보 수집 유효기간 150370

PublicMinsu·2023년 3월 14일
0

문제

접근 방법

날짜는 특정 시간을 기준으로 얼마나 시간이 흘렀는지를 나타내준다. 그것은 가장 작은 단위로 바꾸어도 동일하게 볼 수 있다는 것이다.
연도는 2000~2022이므로 2000년을 기준으로 하면 된다. 1년은 12달이고 모든 달은 모두 동일하게 28일이므로 손쉽게 날짜를 일수로 바꿀 수 있다.

코드

#include <string>
#include <vector>
using namespace std;
int termsToTime[26];
int dateToTime(string date)
{
    string year, month, day;
    year = date.substr(2, 4);
    month = date.substr(5, 7);
    day = date.substr(8, 10);
    return stoi(year) * 336 + stoi(month) * 28 + stoi(day);
}

vector<int> solution(string today, vector<string> terms, vector<string> privacies)
{
    vector<int> answer;
    int todayTime = dateToTime(today);
    for (string term : terms)
    {
        string alpha = term.substr(0, 1), num = term.substr(2);
        termsToTime[alpha[0] - 'A'] = stoi(num) * 28;
    }
    for (int i = 0; i < privacies.size(); ++i)
    {
        string privacie = privacies[i];
        int time = dateToTime(privacie);
        int diff = todayTime - time;
        if (termsToTime[privacie[11] - 'A'] <= diff)
            answer.push_back(i + 1);
    }
    return answer;
}

풀이

일 년은 12달, 한 달은 28일이라는 것을 이용해서 일수로 바꾼 뒤 격차를 확인하면 된다.

profile
연락 : publicminsu@naver.com

0개의 댓글