zcmu-2119

2119: 任意年月日历

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 67   Solved: 18
[ Submit][ Status][ Web Board]

Description

已知2007年1月1日为星期一。
设计一函数按照下述格式打印2007年以后(含)某年某月的日历,2007年以前的拒绝打印。
为完成此函数,设计必要的辅助函数可能也是必要的。其中输入为年分和月份。

Input

Output

Sample Input

Sample Output

Calendar 2007-01--------------------- 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---------------------

HINT

Source

求输出的某年的日历,顺便说一下,这题你不遇到presentation erro的话,就牛逼了   6次的presentation Error,最后

改了自己手写的算天数的代码,取消了引用公式就对了

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<list>
using namespace std;

int y,m;

 
 
int leapYear(int y)
{
	if((y%4==0&&y%100!=0)||y%400==0)return 1;
	return 0;
}

int main()
{
	while(~scanf("%d %d",&y,&m))
	{
		int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
		if(y<2007)break;
		
		int d=1;
		if(leapYear(y))
		{
			a[2]=29;
		}
		
		for(int i=0; i<m; i++)
			d+=a[i];
//		int t=(y-1)+(y-1)/4+(y-1)/400-(y-1)/100+d;//公式,不知道为什么用了却不对
//		t%=7;
		int w = 1;//以下是自己写的求某个月的第一天是星期几的代码
        for ( int i=2007 ; i<y ; i++ )
            if ( leapYear(i) ) w = (w+366)%7;
            else w = (w+365)%7;     
        for ( int i=1 ; i<m ; i++ )
            w = (w+a[i])%7;//
		printf("Calendar %d-%02d\n",y,m);
		puts("---------------------");
		puts(" Su Mo Tu We Th Fr Sa");
		puts("---------------------");
		
		for(int i=0; i<w; i++)
		{
			printf("   ");
		}
		int k=w;
		for(int i=1; i<=a[m]; i++)
		{
			if(k==7)
			{
				k=0;
				puts("");
			}
			printf("%3d",i);
			k++;
		}
		puts("\n---------------------");
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值