哎呀的海角


私信TA

用户名:aiyadehaijiao

访问量:982

签 名:

等  级
排  名 5485
经  验 1475
参赛次数 0
文章发表 2
年  龄 0
在职情况 学生
学  校 海角
专  业

  自我简介:

解题思路:

注意事项:

参考代码:

#include <iostream>

using namespace std;


int main()

{

int year, month;

cin >> year >> month;

//(年份-year)%4==1是闰年,否则都是平年

//月份的计算

int tempYear = year - 2007;

int R = (tempYear+2) / 4;

int P = tempYear - R;

int sumDay = R * 366 + P * 365;

for (int i = 1; i < month; i++)

{

switch (i)

{

case 1:case 3:case 5 :case 7 :case 8:case 10:case 12:sumDay += 31; break;

case 2: 

//闰年

if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)

sumDay += 29;

else

sumDay += 28;

break;

case 4:case 6:case 9:case 11:sumDay += 30; break;

}

}

int week = (sumDay + 1) % 7;

cout << "---------------------" << endl;

cout << " Su Mo Tu We Th Fr Sa" << endl;

cout << "---------------------" << endl;

for (int i = 0; i < week * 2 + week + 1; i++)

cout << " ";

int temp;

switch (month)

{

case 1:case 3:case 5:case 7:case 8:case 10:case 12:temp = 31; break;

case 2:

//闰年

if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)

temp = 29;

else

temp = 28;

break;

case 4:case 6:case 9:case 11:temp = 30; break;

}

for (int i = 1; i <= temp; i++)

{

if (i >= 1 && i <= 9)

cout << " " << i << " ";

else

cout << i << " ";

week = (week + 1) % 7;

if (week == 0&&i!=temp)

cout << endl<<" ";

}

cout << endl;

cout << "---------------------" << endl;

return 0;

}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区