1102: 月份牌
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 48 Solved: 2
[ Submit][ Status][ Web Board]
Description
这里有一份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)的月份牌。
Input
两个数 N M,表示公元N年,M月。
Output
该月的月份牌,注意格式。
Sample Input
2012 12
Sample Output
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
网页好像不太兼容那格式。一直在PE啊,看了后台数据,无语了,手翻万年历,发现后台测试数据竟然是错的,我无语了。
代码如下:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
using namespace std;
int day[13]= { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };// 这时平年各月对应的天数
int mday[13]= { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int firstday[2055]; // 存储每一年第一天是星期几
bool is_spe( int year )
{
if( ( year% 4== 0&& year% 100!= 0 )|| year% 400== 0 )
{
return true;
}
else
{
return false;
}
}
int main( )
{
firstday[2011]= 6;
for( int i= 2010; i>= 1; --i )
{
int curday= is_spe( i )? 366: 365;
curday%= 7;
firstday[i]= firstday[i+ 1]- curday;
if( firstday[i]<= 0 ) firstday[i]+= 7;
}
for( int i= 2012; i<= 2050; ++i )
{
int curday= is_spe( i- 1 )? 366: 365;
curday%= 7;
firstday[i]= firstday[i- 1]+ curday;
firstday[i]%= 7;
if( !firstday[i] ) firstday[i]= 7;
}
int year, mon;
while( scanf( "%d %d", &year, &mon )!= EOF )
{
int fday= firstday[year], num_day, sign;
if( is_spe( year )&& mon> 2 )
{
num_day= day[mon- 1];
}
else
{
num_day= day[mon- 1]- 1;
}
sign= ( fday+ num_day )% 7;
if( !sign ) sign= 7;
int num_mday= ( is_spe( year )&& mon== 2 )? 29: mday[mon];
puts( "Su Mo Tu We Th Fr Sa" );
for( int i= 1; i<= num_mday; ++i )
{
int temp= ( sign+ i )% 7;
for( int j= 0; i== 1&& j< temp; ++j )
{
printf( j== 0? " ": " " );
}
if( temp== 0 )
{
printf( "%2d", i );
}
else if( temp== 6 )
{
printf( "%3d\n", i );
}
else
{
printf( "%3d", i );
}
if( i== num_mday&& temp!= 6 )
{
puts( "" );
}
}
}
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*/