Algorithm/C++ - 프로그래머스

프로그래머스 - 2016년 C++

ㅇㅇ잉 2021. 2. 14. 03:11

윤년이면 2월은 29일, 배열로 각각 요일과 달의 날짜들을 저장한다.

1월 1일은 금요일이라고 했으므로 배열의 day[1]에 "FRI"를 저장해주어

일만큼 더하고 7로 나눈 day배열의 위치값을 계산하여 출력하면 된다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <string>
#include <vector>
#include <iostream>
 
using namespace std;
 
string solution(int a, int b) {
    string answer;
    int tmp=0;
    int mon[12]={31,29,31,30,31,30,31,31,30,31,30,31};
    string day[7]={"THU","FRI","SAT","SUN","MON","TUE","WED"};
    
    for(int i=0;i<a-1;i++){
        tmp+=mon[i];
    }
    answer = day[(tmp+b)%7];
    
    return answer;
}
cs