#define function
- void init(vector<string>& v)
- v[0] = "Monday"
- v[1] = "Tuesday"
- v[2] = "Wednesday"
- v[3] = "Thursday"
- v[4] = "Friday"
- v[5] = "Saturday"
- v[6] = "Sunday"
#main
- int D, M
- cin >> D >> M
- int monthDay[12] = {3, 6, 6, 2, 4, 0, 2, 5, 1, 3, 6, 1} // the first day of each month
- vector<string> days(7)
- init(days)
- int idx = monthDay[M-1]
- int diff = D - 1
- int tmp = diff % 7
- idx += tmp
- if idx > 6
- idx -= 7
- cout << days[idx] << "\n"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
void init(vector<string>& v) {
v[0] = "Monday";
v[1] = "Tuesday";
v[2] = "Wednesday";
v[3] = "Thursday";
v[4] = "Friday";
v[5] = "Saturday";
v[6] = "Sunday";
}
int main()
{
int D, M;
cin >> D >> M;
int monthDay[12] = { 3,6,6,2,4,0,2,5,1,3,6,1 }; // the first day of each month
vector<string> days(7);
init(days);
int idx = monthDay[M - 1]; // 입력받은 달에 해당하는 1일의 요일
int diff = D - 1;
int tmp = diff % 7;
idx += tmp;
if (idx > 6)
idx -= 7;
cout << days[idx] << "\n";
}
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
int d, m;
cin >> d >> m;
// 각 달의 일수
vector<int> month = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
vector<string> days = { "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday" };
// 1월 1일을 기준으로 날수를 계산
int diff_month = m - 1;
int diff_day = d - 1;
for (int i = 0; i < diff_month; i++) {
diff_day += month[i];
}
cout << days[diff_day % 7] << endl;
return 0;
}
Leave a comment