月历

【问题描述】

输入年份和月份, 输出该月的月历。

【输入形式】

输入包含两个整数Y(Y>1920)和M(1<=M<=12),分别表示年份和月份

【输出形式】

阵列式月历,数字间用空格分隔。

【样例输入】

2016 11

【样例输出】
在这里插入图片描述

#include<iostream>
#include<iomanip>
using namespace std;
int tianshu(int x,int y)
{   int c=0;
	if((x%4==0&&x%100!=0)||x%400==0)c=1;
	int d;
	switch(y)
	{
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:d=31;break;
		case 2:d=28+c;break;
		default :d=30;	
	}
	return d;
}
int dyt(int x,int y)
{  
    int a;
     if(x==1921&&y==1)a=7;
	else if(x>1921&&y==1){a=(dyt(x-1,12)+tianshu(x-1,12))%7;} 
	else a=(dyt(x,y-1)+tianshu(x,y-1))%7;
	return a;
}
void tianchong(int x,int y) 
{int a,b,c;
a=dyt(x,y);
b=tianshu(x,y);
c=a;
cout.setf(ios::right);
cout<<"Sun"<<" "<<"Mon"<<" "<<"Tus"<<" "<<"Wed"<<" "<<"Thu"<<" "<<"Fri"<<" "<<"Sat"<<endl;
switch(c)
{
	case (1):{break;}
	case (2):{cout<<"   ";break;}
	case (3):cout<<"       ";{break;}
	case (4):{cout<<"           ";break;}
	case (5):{cout<<"               ";break;}
	case (6):{cout<<"                   ";break;}
	case (0):{cout<<"                       ";break;}
}
for(int i=1;i<=b;i++)
{  
	if(c==7){c=1;cout.width(4);cout<<i<<endl;}
	else if(c==0){c=1;cout.width(4);cout<<i<<endl;}
	else if(c==1){cout.width(3);cout<<i;c+=1;}
	else {cout.width(4);cout<<i;c+=1;}
}
	
}
int main()
{   int x,y;
    cin>>x>>y;
if(x<1921||y<1||y>12)cout<<"error";
else tianchong(x,y);
	return 0;
}  

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值