月份牌
这里有一份2011年的月份牌可以参考
January February March Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 1 2 3 4 5 1 2 3 4 5 2 3 4 5 6 7 8 6 7 8 9 10 11 12 6 7 8 9 10 11 12 9 10 11 12 13 14 15 13 14 15 16 17 18 19 13 14 15 16 17 18 19 16 17 18 19 20 21 22 20 21 22 23 24 25 26 20 21 22 23 24 25 26 23 24 25 26 27 28 29 27 28 27 28 29 30 31 30 31 April May June Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 2 1 2 3 4 5 6 7 1 2 3 4 3 4 5 6 7 8 9 8 9 10 11 12 13 14 5 6 7 8 9 10 11 10 11 12 13 14 15 16 15 16 17 18 19 20 21 12 13 14 15 16 17 18 17 18 19 20 21 22 23 22 23 24 25 26 27 28 19 20 21 22 23 24 25 24 25 26 27 28 29 30 29 30 31 26 27 28 29 30 July August September Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 2 1 2 3 4 5 6 1 2 3 3 4 5 6 7 8 9 7 8 9 10 11 12 13 4 5 6 7 8 9 10 10 11 12 13 14 15 16 14 15 16 17 18 19 20 11 12 13 14 15 16 17 17 18 19 20 21 22 23 21 22 23 24 25 26 27 18 19 20 21 22 23 24 24 25 26 27 28 29 30 28 29 30 31 25 26 27 28 29 30 31 October November December Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 1 2 3 4 5 1 2 3 2 3 4 5 6 7 8 6 7 8 9 10 11 12 4 5 6 7 8 9 10 9 10 11 12 13 14 15 13 14 15 16 17 18 19 11 12 13 14 15 16 17 16 17 18 19 20 21 22 20 21 22 23 24 25 26 18 19 20 21 22 23 24 23 24 25 26 27 28 29 27 28 29 30 25 26 27 28 29 30 31 30 31
请编程实现输出给定年份(1-2050),给定月份(1-12)的月份牌。
输入
两个数 N M,表示公元N年,M月。
输出
该月的月份牌,注意格式。
样例输入
2012 12
样例输出
Su Mo Tu We Th Fr Sa
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
---------------------------------------------------------------------------------------------
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#define _OJ_
int
Howdays(int year, int month, int day)
//查看这个月的第一天是这一年的第几天
{
int day1;
day1 = day;
switch (month - 1) {
case 11: day1 += 30;
case 10: day1 += 31;
case 9: day1 += 30;
case 8: day1 += 31;
case 7: day1 += 31;
case 6: day1 += 30;
case 5: day1 += 31;
case 4: day1 += 30;
case 3: day1 += 31;
case 2:
if((year % 4 == 0 && year % 100 != 0 ) || (year % 400) == 0)
day1 += 29;
else
day1 += 28;
case 1: day1 += 31;break;
}
return day1;
}
int
Howday1(int year, int month)
//查看这个月有多少天
{
int day1;
switch (month) {
case 12: day1 = 31; break;
case 11: day1 = 30; break;
case 10: day1 = 31; break;
case 9: day1 = 30; break;
case 8: day1 = 31; break;
case 7: day1 = 31; break;
case 6: day1 = 30; break;
case 5: day1 = 31; break;
case 4: day1 = 30; break;
case 3: day1 = 31; break;
case 2:
if((year % 4 == 0 && year % 100 != 0 ) || (year % 400) == 0)
{day1 = 29; break;}
else
day1 = 28; break;
case 1: day1 = 31; break;
}
return day1;
}
int main(int argc, char const *argv[]) {
#ifndef _OJ_ //ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
int mon_day, cnt, d, i;
int year, month, day;
scanf("%d %d", &year, &month);
d = Howdays(year, month, 1);
int reslut = ((year-1) + ((year-1)/4) - ((year-1)/100) + ((year-1)/400) + d) % 7;
//Y是年数d是第几天
mon_day = Howday1(year, month);
printf("Su Mo Tu We Th Fr Sa\n");
switch (reslut) {
case 1:printf(" "); break;
case 2:printf(" "); break;
case 3:printf(" "); break;
case 4:printf(" "); break;
case 5:printf(" "); break;
case 6:printf(" ");break;
}//第一天应该输出的空格
// printf("%d\n", reslut);
cnt = reslut;
for(i = 1;i <= mon_day - 1; i++) {
if(1 <= i && i<= 9 && cnt == 6) printf(" %d", i);
else if(1 <= i && i<= 9) printf(" %d ", i);
else if(i >= 10 && cnt == 6) printf("%d", i);
else printf("%d ", i);
if(cnt == 6) {
printf("\n"); cnt = -1;
}
cnt++;
}
printf("%d\n", mon_day);
return 0;
}
// Su Mo Tu We Th Fr Sa
// 1
// 2 3 4 5 6 7 8
// 9 10 11 12 13 14 15
// 16 17 18 19 20 21 22
// 23 24 25 26 27 28 29
// 30 31