解题思路:
注意事项:
参考代码:
#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 人评分
A+B for Input-Output Practice (II) (C语言代码)浏览:999 |
C语言程序设计教程(第三版)课后习题8.5 (C语言代码)浏览:543 |
【矩阵】 (C++代码)浏览:949 |
【蟠桃记】 (C语言代码)浏览:1034 |
完数 (C语言代码)浏览:693 |
幸运数 (C++代码)浏览:1264 |
DNA (C语言代码)浏览:394 |
C二级辅导-求偶数和 (C语言代码)浏览:673 |
2006年春浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:344 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:754 |