解题思路:
注意事项:
参考代码:
#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 人评分
C语言程序设计教程(第三版)课后习题10.7 (C语言代码)浏览:511 |
矩形面积交 (Java代码)浏览:1213 |
c primer plus 第十二章 12.1小节浏览:376 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:578 |
C语言程序设计教程(第三版)课后习题8.1 (C语言代码)浏览:1242 |
wu-淘淘的名单 (C++代码)浏览:1331 |
愚蠢的摄影师 (C++代码)浏览:933 |
1035 题解浏览:778 |
钟神赛车 (C语言代码)浏览:590 |
单词个数统计 (C语言代码)浏览:1009 |