如果输入1月1日,则计算某一年内落在13日的周一数(没有闰年的考虑)C++。
我已经找到了 这个 StackOverflow上的Q&A,但似乎太复杂了,我的作业问题。我只是一个数学专业的大一学生,而且是C++的初学者。因此,我想知道是否有更简单、更初级的方法来解决这个问题?
好吧,我在写完下面的小代码后就卡住了......
#include <bits/stdc++.h>
using namespace std;
int main()
{
enum Month = {Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec};
enum week_day = {Mon, Tue, Wed, Thurs, Fri, Sat, Sun};
int jan1;
cin>>jan1
}
因为我无法确定什么是计算问周一的最佳方法,如何用代码写出来。
先谢谢你了。
我不会帮你做功课,但这里有一些代码可以让你入门。
int monthdays[] = [0,31,28,31,30,31,30,31,31,30,31,30,31];
int day = 1;
int month = 1;
int week_day = 0; // monday is 0, tuesday is 1, ... you initialize this based on user input
int monday13count = 0;
while (month <= 12)
{
// your code goes here
// evaluate if this is "monday the 13th" => increment monday13count
// increment day and week_day.
// adjust for end of month condition
}