-
연습 문제 : 프로그래머스 LEVEL 1(2016년) - 사용 언어 : C++ - 해결 날짜 : 2021-01-25
**- 해결 방법** : 우선 입력받은 a월 이전 달 까지의 일수를 세기 위해 while문과 switch문을 활용하였다. 1월 1일이 금요일이기 때문에 vector에 목요일부터 수요일까지 순서대로 저장하여 vec[1]이 금요일이 되도록 하였고, a월의 b일 까지 모든 일수를 더해 7로 나눈 나머지로 무슨 요일인지 알 수 있었다. - 코드 ``` #include <string> #include <vector> using namespace std; string solution(int a, int b) { //366일 vector<string> vec = {"THU", "FRI", "SAT", "SUN", "MON", "TUE", "WED"}; int temp_month = 1; int total_day = 0; while(temp_month != a){ switch(temp_month){ case 1: case 3: case 5: case 7: case 8: case 10: case 12: temp_month++; total_day += 31; break; case 2: temp_month++; total_day += 29; break; case 4: case 6: case 9: case 11: temp_month++; total_day += 30; break; default: break; } } total_day += b; int day = total_day % 7; string answer = vec[day]; return answer; } ```