文章
36
粉丝
505
获赞
102
访问
380.5k
思路很简单,就是先算出来目标日期距离4月12日有多少天
最后加上4再对7取模就是目标日期的星期数
#include<iostream>
using namespace std;
int main()
{
int days[13] = {0,0,0,0,30,31,30,31,31,30,31,30,31 };
int m, d, cntday = 0;
cin >> m >> d;
for (int i = 4; i < m; i++)
cntday += days[i];
cntday = cntday - 12 + d;
switch ((cntday + 4) % 7)
{
case 0:cout << "Sunday"; break;
case 1:cout << "Monday"; break;
case 2:cout << "Tuesday"; break;
case 3:cout << "Wednesday"; break;
case 4:cout << "Thursday "; break;
case 5:cout << "Friday"; break;
case 6:cout << "Saturday"; break;
}
return 0;
}
登录后发布评论