코딩공부/프로그래머스

[프로그래머스]Lv1 개인정보 수집 유효기간 C++

usingsystem 2023. 8. 11. 17:00
728x90

https://school.programmers.co.kr/learn/courses/30/lessons/150370?language=cpp 

 

프로그래머스

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

programmers.co.kr

소스코드

#include <string>
#include <vector>
#include <map>
#include <sstream>
using namespace std;

vector<int> solution(string today, vector<string> terms, vector<string> privacies) {
 vector<int> answer;

	int year = stoi(today.substr(0, 4));
	int month = stoi(today.substr(5, 2));
	int day = stoi(today.substr(8, 2));

	int totalDay = ((year * 12) * 28) + ((month) * 28) + day;

	map<char, int> m;
	for (int i = 0; i < terms.size(); i++)
	{
		stringstream stream(terms[i]);

		char alpha;
		int month;

		stream >> alpha >> month;
		m.insert({ alpha, month });
	}

	for (int i = 0; i < privacies.size(); i++) {
		int year = stoi(privacies[i].substr(0, 4));
		int month = stoi(privacies[i].substr(5, 2));
		int day = stoi(privacies[i].substr(8, 2));
		char alpha = privacies[i].back();
		
		 int targetDay = ((year * 12) * 28) + ((month) * 28) + day + ((m[alpha] * 28) - 1);

		 if (totalDay > targetDay)
			 answer.push_back(i + 1);
	}

	return answer;
}
728x90