[프로그래머스 C++] 개인정보 수집 유효기간
[프로그래머스 C++] 개인정보 수집 유효기간
https://school.programmers.co.kr/learn/courses/30/lessons/150370
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
해결전략
문자열
정답코드
#include <iostream> #include <string> #include <vector> #include <map> using namespace std; map<string, int> myMap; vector<int> solution(string today, vector<string> terms, vector<string> privacies) { vector<int> answer; int tYear = stoi(today.substr(0,4)); int tMonth = stoi(today.substr(5,2)); int tDay = stoi(today.substr(8,2)); //cout << tyear << ", " << tmonth << ", " << tday << "\n"; for(int i = 0; i < terms.size(); i++){ string alpha = terms[i].substr(0,1); int beta = stoi(terms[i].substr(2)); //cout << alpha << ", " << beta << "\n"; myMap[alpha] = beta; } 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)); string term = privacies[i].substr(11,1); //cout << year << ", " << month << ", " << day << ", " << term << "\n"; int newYear = year; int newMonth = month; int newDay = day; if(myMap.find(term) != myMap.end()) { if(myMap[term] == 0) continue; newMonth += myMap[term]; if(newDay == 1){ newDay = 28; newMonth--; } else{ newDay--; } if (newMonth > 12) // 12 초과인 경우 -1 한 후 연산해야 한다. { newYear += (newMonth - 1) / 12; newMonth = (newMonth - 1) % 12 + 1; } } if(newYear < tYear) answer.emplace_back(i+1); else if(newYear == tYear && newMonth < tMonth) answer.emplace_back(i+1); else if(newYear == tYear && newMonth == tMonth && newDay < tDay) answer.emplace_back(i+1); } return answer; }
'⭐ 코딩테스트 > 프로그래머스' 카테고리의 다른 글
[프로그래머스 C++] 양궁대회 (0) | 2024.05.14 |
---|---|
[프로그래머스 C++] 카카오프렌즈 컬러링북 (0) | 2024.04.28 |
[프로그래머스 C++] 3 x n 타일링 (0) | 2024.04.22 |
[프로그래머스 C++] 요격 시스템 (0) | 2024.04.05 |
[프로그래머스 C++] 등굣길 (0) | 2024.04.02 |
댓글
이 글 공유하기
다른 글
-
[프로그래머스 C++] 양궁대회
[프로그래머스 C++] 양궁대회
2024.05.14 -
[프로그래머스 C++] 카카오프렌즈 컬러링북
[프로그래머스 C++] 카카오프렌즈 컬러링북
2024.04.28 -
[프로그래머스 C++] 3 x n 타일링
[프로그래머스 C++] 3 x n 타일링
2024.04.22 -
[프로그래머스 C++] 요격 시스템
[프로그래머스 C++] 요격 시스템
2024.04.05
댓글을 사용할 수 없습니다.