输入年月,输出日历 这个程序怎么写
不要什么太复杂的函数什么的
#include<iostream>
#include<iomanip>
using namespace std;
int nyear(int year)
{
if(year%400==0||(year%4==0&&year%100!=0))
return 366;
else
return 365;
}
int nmonth(int m,int y) //根据年份和月份,判断是那一个月的天数
{
if(m==1||m==3||m==5||m==7||m==8||m==10||m==12)
return 31;
else if(nyear(y)==366&&m==2)
return 29;
else if(nyear(y)==365&&m==2)
return 28;
else
return 30;
}
int getDays(int year, int month)
{
int i;
int sum=0;
if(year>1900)
for(i=1900;i<year;i++)
sum+=nyear(i);
if(month>1)
for(i=1;i<month;i++)
sum+=nmonth(i,year);
return sum;
}
int main()
{
int i,j,year,month,day,sum,daycount,cases=1;
while(cin>>year>>month)
{
sum=getDays(year,month);
day=sum%7;
daycount=nmonth(month,year);
cout<<"Case "<<cases++<<": "<<year<<"年"<<month<<"月"<<endl;
cout<<"Mon Tue Wed Thu Fri Sat Sun"<<endl;
for(i=0;i<day%7;i++)
cout<<" ";//
for(i=1,j=day+1;i<=daycount;i++,j++)
{
cout<<setw(4)<<setiosflags(ios::left)<<i;
if(j%7==0) cout<<endl;
}
cout<<endl;
}
return 0;
}